#include"iostream"
using namespace std;
class complex{//定义一个复数类
public:
double real,imag;//定义实数和虚数
complex(double r=0.0,double i=0.0):real(r),imag(i) { }//构造函数赋值
complex operator-(const complex &c);//类内“减号”重载
};
//类外“加号”重载
complex operator+(const complex &a,complex &b){
return complex(a.real+b.real,a.imag+b.imag);
}
complex complex::operator-(const complex &a){
return complex(real - a.real,imag - a.imag);
}
int main(){
complex a(4,4),b(2,2),c;
c=a+b;
cout<<c.real<<","<<c.imag<<endl;
cout<<(a-b).real<<","<<(a-b).imag<<endl;
}
07-31
09-13
480