#include<iostream>
using namespace std;
class Complex
{
public:
//构造函数
Complex(double real=0.0,double image=0.0)
:_real(real)
,_image(image)
{}
//拷贝构造函数
Complex(const Complex& c)
{
_real=c._real;
_image=c._image;
}
//赋值运算符重载
Complex& operator=(const Complex& c)
{
if(this!=&c)
{
_real=c._real;
_image=c._image;
}
return *this;
}
//析构函数
~Complex()
{
}
public:
Complex operator+(const Complex& c)
{
Complex temp;
temp._real=_real+c._real;
temp._image=_image+c._image;
return temp;
}
Complex& operator+=(const Complex& c)
{
Complex temp(*this);
this->_real=_real+c._real;
this->_image=_image+c._image;
return *this;
}
Complex operator-(const Complex& c)
{
Complex temp;
temp._real=_real-c._real;
temp._image=_image-c._image;
return temp;
}
Complex& operat
C++--实现简单的复数类
最新推荐文章于 2023-08-16 15:47:22 发布