输出是 5500,但为什么不是 5555?
class product {
public:
int b;
};
class item {
public:
int a;
item(product& obj)
{
cout << a;
}
item() {}
void display()
{
cout << a;
}
};
int main()
{
item obj1;
product obj2;
obj1.a = 5;
cout << obj1.a;
obj1.display();
obj1 = obj2;
//object of product class sent into Constructor of item class*
cout << obj1.a;
return 0;
}
这里调用项目类的构造函数,并通过它传递产品对象。