class Test
{public:
Test() {cout<<"default constructor"<<endl;}
~Test() {cout<<"default destructor"<<endl;}
Test(int i):a(i){cout<<"from copy"<<endl;}
Test(const Test&) {cout<<"copy constructor"<<endl;}
private:
int a;};
Test play(Test b)
{ return b;}
int main()
{
Test a;
cout<<"********"<<endl;
play(a);
return 0;
}
结果:
default constructor0x28ff04
copy constructor0x28ff0c
copy constructor0x28ff08
default destructor0x28ff08
default destructor0x28ff0c
default destructor0x28ff04
在函数调用过程中的情况:传值