C++ &引用;“没有匹配功能”;在自定义类型上使用push_时调用错误

C++ &引用;“没有匹配功能”;在自定义类型上使用push_时调用错误,c++,push-back,C++,Push Back,我在尝试推回自定义类型的对象时遇到此错误。代码如下: class Item_base { public: Item_base(string isbn=" ", int num=0):book(isbn),number(num){} Item_base(Item_base &I):book(I.book),number(I.number){cout<<"\nCopy Constructor"<<endl;}

我在尝试推回自定义类型的对象时遇到此错误。代码如下:

class Item_base    
{
    public:     
    Item_base(string isbn=" ", int num=0):book(isbn),number(num){}    
    Item_base(Item_base &I):book(I.book),number(I.number){cout<<"\nCopy Constructor"<<endl;}    
    Item_base &operator=(Item_base &d){if (this != &d){this->book=d.book;this->number=d.number;cout<<"\nAssignment Operator"<<endl;return *this;}else{cout<<"\nAssignment Operator"<<endl;return *this;}}    
    ~Item_base(){cout<<"Item_base Destructor"<<endl;}   
    protected:    
    string book;     
    int number;    
};


#include <iostream>   
using namespace std;
#include <vector>
#include "Item_base.h"
int main (int argc, char * const argv[]) {    
    // insert code here...    
    vector<Item_base> vecbase;     
    Item_base derivo("Harry Potter",10);     
    cout<<"enter book name, qty, dqty"<<endl;     
    vecbase.push_back(derivo);     
    return 0;   
}
class项目库
{
公众:
Item_base(字符串isbn=”“,int num=0):book(isbn),number(num){

Item_-base(Item_-base&I):book(I.book),number(I.number){coutVector只有两个push_-back函数的实现

  • 向后推(常数&)
  • 向后推(T&)
    (从C++11开始)

这就解释了为什么我们需要为我们的类提供带有参数
const T&
的复制构造函数

非常感谢它的工作。这是否意味着push_back调用复制构造函数?@johanneschaub litb,因为vector只有两个重载函数push_back-带有参数
const T&
T&
(从C++11开始)。@AzeruddinSheikhAzeemuddinSh,是的,我认为Johannes的观点是在答案中包含解释是非常有用的。这肯定会使这个答案更好。