//加号运算符重载
#include
using namespace std;
class p1
{
public:
int a1;
int a2;
};
p1 operator+(const p1& p,p1& p2)
{
p1 temp;
temp.a1 = p.a1 + p2.a1;
temp.a2 = p.a2 + p2.a2;
return temp;
}
void z()
{
p1 one;
one.a1 = 10;
one.a2 = 20;
p1 two;
two.a1 = 30;
two.a2 = 40;
p1 three = (one + two);
cout << three.a1 << endl;
cout << three.a2 << endl;
}
int main()
{
z();
system(“pause”);
}