[求助]关于操作符的重载问题
#include <iostream> using namespace std;
class Test
{
public:
Test(int a)
{
Test::a = a;
}
Test operator + (Test &temp) //就是这个函数
{
Test result(this->a + temp.a);
return result;
}
public:
int a;
};
int main()
{
Test a(100);
a = a + Test(10);
a = Test(10) + a;
cout<<a.a<<endl;
a = 50 + 1;
cout<<a.a<<endl;
system("pause");
return 0;
}