正在加载图片...
5:06:48 运算符重载 通过在类中建立运算符函数( operator function)实现 声明运算符函数的一般形式为 返回值类形 operator运算符(形参运算量列表); 例;复数的加法 class complex float real, image, public Complex (float r=0, float i=0) Complex (const Complex c Complex operator +(const Complex right) void maino[ Complex left(1, 2), right(3, 4) Complex result: result left right15:06:48 运算符重载 通过在类中建立运算符函数(operator function)实现 声明运算符函数的一般形式为 返回值类形 operator 运算符(形参运算量列表); 例:复数的加法 class Complex{ float real,image; public: Complex (float r=0,float i=0); Complex (const Complex & c); Complex operator +(const Complex & right); }; void main(){ Complex left(1,2),right(3,4); Complex result; result = left + right; }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有