#include <iostream>
using namespace std;
class Test{
public:
Test(){
i_test = 0;
};
Test(int a){
i_test = a;
};
Test operator ++();
Test operator +(Test &obj);
Test operator =(Test &obj);
public:
int i_test;
}
Test::operator ++(){
++i_test;
return *this;
}
Test Test::operator +(Test &obj){
Test tempObj;
tempObj.i_test = i_test + obj.i_test;
return tempObj;
}
Test Test::operator =(Test &obj){
i_test = obj.i_test;
return *this;
}
int main(){
Test myObj1(1),myObj2(2),resultObj;
resultObj = myObj1 + myObj2;
cout << resultObj.i_test << endl;
return 0;
}
运行如下: