#include"iostream"
class Complex{
public:
Complex(double r=0,double i=0){
real = r;
img = i;
}
Complex operator+(const Complex &);
Complex operator-(const Complex &);
double real;
double img;
};
Complex Complex::operator+(const Complex& op2){
return Complex(op2.real + real, op2.img + img);
}
Complex Complex::operator-(const Complex& op2){
return Complex(real - op2.real, img - op2.img);
}
using namespace std;
int main(){
Complex y(5.2, 1.3), z(4.4, 7.7);
Complex x(y);
z = x + y;
z = x - y;
return 0;
}
网友评论