没注释的源代码
#include <iostream>
using namespace std;
class Complex
{
public:
Complex(){real=0;imag=0;}
Complex(double r,double i){real=r;imag=i;}
Complex operator+(Complex &c2)
{

Complex c;
c.real=real+c2.real;
c.imag=imag+c2.imag;
return c;
}
double get_real()
{
return real;
}
double get_imag()
{
return imag;
}
Complex operator+(int &i)
{
Complex c;
c.real=real+i;
c.imag=imag;
return c;
}
void display()
{
cout<<"("<<real<<","<<imag<<"i)"<<endl;
}
friend Complex operator+(int &i,Complex &c2);
private:
double real;
double imag;
};
Complex operator+(int &i,Complex &c2)
{
Complex c;
c.real=i+c2.real;
c.imag=c2.imag;
}
int main()
{
Complex c1(3,4),c2(5,-10),c3;
int i=5;
c3=c1+c2;
c3.display();
c3=i+c1;
c3.display();
c3=c1+i;
c3.display();
return 0;
}