正在加载图片...
第8章多态性 8.1运算符重载 81.1问题的提出 例6.3的复数类 CComplex CComplex: Add(ccomplex c) include iostream h class CComplex CComplex temp; private: temp real real + c real; double real; temp imag imag C imag; double imag return temp; public CComplex(double r, double i);i CComplex CComplex: Sub(CComplex c) void print(; CComplex Add (ccomplex c); CComplex temp; cComplex Sub(CComplex c); temp. real real -C real; temp imag imag-C imag; return temp;8.1 运算符重载 8.1.1 问题的提出 例6.3的复数类 #include "iostream.h" class CComplex { private: double real; double imag; public: CComplex(double r, double i); void Print(); CComplex Add(CComplex c); CComplex Sub(CComplex c); }; 第8章 多态性 CComplex CComplex::Add(CComplex c) { CComplex temp; temp.real = real + c.real; temp.imag = imag + c.imag; return temp; } CComplex CComplex::Sub(CComplex c) { CComplex temp; temp.real = real - c.real; temp.imag = imag - c.imag; return temp; }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有