有如下程序:#includeusing namespace std;class Complex{double re, im;public:Complex(dou
有如下程序:
#include
using namespace std;
class Complex
{
double re, im;
public:
Complex(double r, double i):re(r), im(i){}
double real() const{return re;}
double image() const{return im;}
Complex& operator +=(Complex a)
{
re += a.re;
im += a.im;
return *this;
}
};
ostream &operator<<(ostream& s,const Complex& z)
{
return s<<'('<
}
int main()
{
Complex x(1, -2), y(2, 3);
cout<<(x += y)<
return 0;
}
执行这个程序的输出结果是
A . (1, -2)
B . (2, 3)
C . (3, 5)
D . (3, 1)