#include<iostream>
using namespace std;
class Complex
{
public:
int a;
int b;
friend ostream& operator<<(ostream &out, Complex c3);
public:
Complex(int a=0,int b=0)
{
this->a = a;
this->b = b;
}
void printfM()
{
cout << "a:"<<this->a<<" b:"<<this->b<< endl;
}
Complex operator+ (Complex c)
{
Complex tmp(a + c.a, b + c.b);
return tmp;
}
};
ostream& operator<<(ostream &out, Complex c3)
{
out << "a="<<c3.a<<" b=" << c3.b;
return out;
}
//运算符重载的正确写法:<< >>使用友元函数 其他运算重载函数写在类的内部
void main()
{
Complex c1(1, 2);
Complex c2(2, 3);
Complex c3 = c1 + c2;
//c3.printfM();
cout << c3;
system("pause");
}