单选题 有如下程序: #include<iostream> using namespace std; class Complex { double re,im; public: Complex(double r,double i):re(r);im(i){} double real()const{fetum re;} double image()const{return im;} Complex&operator+=(Complex a) { re+=a.re; im+=a.im;return*this: } }; ostream& operator<<(ostrearn& s,const Complex&z) { return s<<'('<<z.real()<<','<<z.image()<<')'; } int main() { Complex x(1,-2),y(2,3); cout<<(x+=y)<<endt; return 0: } 执行这个程序的输出结果是( )。
【正确答案】 D
【答案解析】解析:此题考查了运算符重载应用。因为x和y都是Complex类的对象,Complex类中已经重载了+=运算符,表达式x+=y就等价与x.operator+=(y),执行后得到(3,1);接着计算cout<<(x+=y),其等价于调用operator<<(cout,(x+=y)),最后输出结果是(3,1)。