Microsoft PowerPoint - 第8章 操作符重载.pdf
文本预览下载声明
yangyu@bupt.edu.cn
C++
2012/12/12 C++ 2
2012/12/12 C++ 3
2012/12/12 C++ 4
Complex
class Complex{ Complex::Add(Complex c)
double real; { Complex ret;
double image; ret.image = image + c.image;
public: ret.real = real + c.real;
Complex(double r = 0, return ret;}
double i = void Complex::Show()
0):real(r),image(i){}; {
Complex Add(Complex c); cout ( real , i
void Show(); image );
}; 2012/12/12 C++ } 5
Complex *this = c1;
Complex c = c2;
int main(void)
{Complex c1(1.0, 1.0), c2(2.0, 2.0), c3;
1 ret
c3 = c1.Add(c2); 2 ret.real = real + c.real
cout c1 = ;c1.Show();cout endl;
cout c2 = ;c2.Show();cout endl; ret.real = c1.real + c2.real
cout c1 + c2 =
显示全部