我写了一个简单的代码,我的问题是:为什么item_base只调用constrcut函数?应该item_base调用“复制构造函数”吗?我观察到当我创建item_base2时,它调用了“复制构造函数”,但item_base不调用“复制构造函数”。有什么区别?
class Item_base {
public:
Item_base();
Item_base(int);
Item_base(const Item_base &base);
void operator=(const Item_base &item);
virtual ~Item_base();
};
Item_base::Item_base()
{
cout << "construct function" << endl;
}
Item_base::Item_base(int a)
{
cout << "arg construct function" << endl;
}
Item_base::Item_base(const Item_base &base)
{
cout << "copy function" << endl;
}
void Item_base::operator=(const Item_base &item)
{
cout << "= operator" << endl;
}
Item_base::~Item_base()
{
}
int main()
{
//cout << "Hello world!" << endl;
Item_base item_base = Item_base(1);//construct function
Item_base item_base2 = item_base;//copy construct function
Item_base item_base3;
item_base3 = item_base2;// =operator function
return 0;
}