老师,您好!
Complex Complex::operator+(const Complex& x) {
//Complex tmp;
//// tmp._real = tmp._image=0;
//tmp._real = _real + x._real;
//tmp._image = _image + x._image;
//return tmp;
return Complex(_real + x._real, _image + x._image);
}
Complex& Complex::operator=(const Complex& x) {
if (this != &x) {
_real = x._real;
_image = x._image;
}
return *this;
}
Complex c=a+b;
我进行断点跟踪发现,运行到
return Complex(_real + x._real, _image + x._image);
这一步,有下面的情况
发现是对c的直接初始化,然后那个赋值操作就不存在了。这个不是很懂