#include <iostream>
using namespace std;
class Complex
{
private:
	double real;                                
	double imag;                             
public:
	Complex();                                
	Complex(double r,double i);				  
	Complex operator + (Complex &t1);            //重载运算符“+”
	friend ostream&operator << (ostream &,Complex &);//重载运算符“<<”         
};
int main()
{
	Complex t1(1,2);                           //定义对象t1
	Complex t2(3,4);			  //定义对象t2
	Complex t3;                              //定义对象t3
	t3=t1+t2;                                //运用重载运算符直接对类对象相加
	cout<<"this complex is: "<<t3;		//运用重载运算符直接输出类对象
}
Complex::Complex()                            

{
	real=0;
	imag=0;
}
Complex::Complex(double r,double i)
{
	real=r;
	imag=i;
}
Complex Complex::operator + (Complex &t1)        //定义运算符重载
{
	Complex t;                                
	t.real=this->real+t1.real;                
	t.imag=this->imag+t1.imag;                 
	return t;
}
ostream&operator << (ostream &output,Complex &t)  //定义运算符重载
{
	output<<"("<<t.real<<"+"<<t.imag<<"i)"<<endl;
	return output;
}

