为什么这个拷贝构造函数执行了四次,两次传参是反过来的吗
CAssembly::CAssembly(Part xone, Part xtwo)
: one(xone), two(xtwo), date(10)
{
cout << " good_2! Constructor of Class CAssembly called" << endl;
Part::Part() : val(0)
{
cout << " good_1! Default Constructor of Class Part called" << ", val = " << val << endl;
}
Part::Part(int i) : val(i)
{
cout << " good_2! Constructor1 of Class Part called" << ", val = " << val << endl;
}
Part::Part(Part& pt)
{
val = pt.val;
cout << " well! Copy Constructor of Class Part called" << ", val = " << val << endl;
Part:: ~Part()
{
cout << " over! Destructor of Class Part called" << endl;
}
Part one; //构造对象:配件1 ,val = 0 ;
Part two(10);
CAssembly myAssC(one, two);
输出结果
well!Copy Constructor of Class Part called, val = 10
well!Copy Constructor of Class Part called, val = 0
well!Copy Constructor of Class Part called, val = 0
well!Copy Constructor of Class Part called, val = 10
good_2!Constructor of Class CAssembly called
over!Destructor of Class Part called
over!Destructor of Class Part called