猿问

不同类型数据间的转换问题

#include <iostream> using namespace std; class complex {public: complex(double r = 0, double i = 0) :real(r), imag(i){} complex(double r){ real = r; imag = 0; } friend complex operator +(complex c1, complex c2) { return complex(c1.real + c2.real, c1.imag + c2.imag); } void display() { cout << "(" << real << "," << imag << "i)" << endl; } private: double real, imag; }; int main() { complex c1(3, 4), c2(5, -10), c3; c3=c1+2.5; c3.display(); system("pause"); return 0; } 主函数的c3=c1+2.5的加号会显示“没有与这些操作数匹配的“+”运算符操作数类型为:complex+double”
2015071819
浏览 1270回答 1
1回答
随时随地看视频慕课网APP
我要回答