64,654
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
class Test
{
public:
int a;
Test(int x) {
a = x;
}
Test(const Test& test) {
cout <<"copy constructor" <<endl;
a = test.a;
}
Test& operator= (const Test& t) {
cout <<"operator=" <<endl;
a = t.a;
}
};
void fun1(Test test)
{
cout <<"fun1()..." <<endl;
}
Test fun2(void)
{
Test t(2);
cout <<"fun2()..." <<endl;
return t;
}
int main()
{
Test t1(1);
Test t2 = t1;
cout <<"before fun1()..." <<endl;
fun1(t1);
Test t3 = fun2();
cout <<"after fun2()..." <<endl;
system("pause");
return 0;
}