小白求助 拷贝构造函数出问题了
#include "iostream"using std::endl;
using std::cin;
using std::cout;
using std::ostream;
class Test
{
private:
int a;
int b;
public:
Test()
{
}
public:
Test(int a, int b)
{
this->a = a;
this->b = b;
}
public:
Test(const Test& obj)
{
this->a = obj.a + 10;
this->b = obj.b + 10;
}
public:
friend ostream& operator<<(ostream& cout, Test t);
};
ostream& operator<<(ostream& cout, Test t)
{
cout << t.a << " " << t.b << endl;
return cout;
}
Test fun2()
{
Test t4(222, 333);
return t4;
}
void main()
{
Test t1 = fun2();
cout << t1 << endl;
Test t2;
t2 = fun2();
cout << t2 << endl;
system("pause");
}
/*问题 打印结果为啥是242 353 不是 232 343
242 353
242 353
*/