64,639
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
class test
{
public:
test()
{
m_i = 1;
cout << "test::ctor()" << endl;
}
test(const test& t)
{
cout << "test::cctor()" << endl;
//m_i = t.m_i;
m_i = 111;
}
~test()
{
//cout << "test::dtor()" << endl;
cout << "test::dtor(" << m_i << ")" << endl;
}
test& operator=(const test& t)
{
cout << "test::=()" << endl;
return *this;
}
public:
int m_i;
};
test myfunc()
{
test m;
m.m_i = 100;
return m;
}
int main()
{
//test t;
//test t2(t);
//t2.m_i = 2;
cout << "1" << endl;
test t = myfunc();
cout << "m_i is: " << t.m_i << endl;
t.m_i = 888;
//test t;
//test t2;
//t2 = t;
cout << "2" << endl;
return 0;
}