关于c++复数设计 运行有错误求解决#includevoid 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
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/23 16:31:17
关于c++复数设计 运行有错误求解决#includevoid 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
关于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
关于c++复数设计 运行有错误求解决#includevoid 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 &operator