64,646
社区成员
发帖
与我相关
我的任务
分享
class complex
{
public:
complex( double real_ = 0, double imag_ = 0 ): real(real_), imag(imag_){}
complex& operator += ( const complex& other )
{
real += other.real;
imag += other.imag;
return *this;
}
friend const complex operator + ( const complex& lhs, const complex & rhs )
{
complex tmp( lhs );
tmp += rhs;
return tmp;
}
//complex operator + (complex c2);
private:
double real;
double imag;
};
//complex complex::operator(complex c2)
//{
// return complex(real+c2.real,imag+c2.imag);
//}
int main()
{
complex c1(5,4),c2(2,10),c3;
c3=c1+c2;
return 0;
}