作业帮 > 综合 > 作业

关于c++复数设计 运行有错误求解决

来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/04/29 05:47:34
关于c++复数设计 运行有错误求解决
#include
void fushu(){ class Complex { double real; double imag; }; Complex operator+(Complex c1,Complex c2) { Complex c; c.real=c1.real+c2.real; c.imag=c1.imag+c2.imag; return c; } ostream&operator
修改后:
#include
class Complex
{
private:
double real;
double imag;
public:
Complex()
{
}
Complex(double r,double i)
{
real = r;
imag = i;
}
Complex operator+(Complex c2)
{
Complex c;
c.real=real+c2.real;
c.imag=imag+c2.imag;
return c;
}
Complex operator= (Complex &other)
{
this->real=other.real;
this->imag=other.imag;
return *this;
}
friend ostream &operato