1)对象作为函数参数,以值传递的方式
2)函数返回值为对象
3)用对象给另一个对象初始化
#include <iostream>
using namespace std;
class Test
{
int m_i;
int m_j;
public:
Test()
{
cout<<"Test()"<<endl;
}
Test(Test& a)
{
cout <<"Test(Test& a)"<<endl;
}
Test(int v)
{
cout<<"Test(int v)"<<endl;
}
~Test()
{
cout<<"~Test()"<<endl;
}
};
Test Play(Test t)
{
cout << "....." << endl;
return t;
}
int main()
{
Test t = Play(5);
return 0;
}
/*输出*/
// Test(int v)
// Test(Test& a)
// .....
// Test(Test& a)
// ~Test()
// ~Test()
int main()
{
Play(5);
return 0;
}
/*输出*/
// Test(int v)
// .....
// Test(Test& a)
// ~Test()
// ~Test()