尝试推回自定义类型的对象时出现此错误。代码如下:
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;
}
我得到的错误信息是:
错误:没有用于调用 'Item_base::Item_base(const Item_base&)' 的匹配函数
有人可以帮我弄这个吗?我是编程新手