#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”
1 回答
- 1 回答
- 0 关注
- 1269 浏览
添加回答
举报
0/150
提交
取消