代码实现:
#include <iostream>
using namespace std;
class Complex
{
public:
Complex(int real = 0,int image = 0)
:mReal(real),mImage(image){}//构造函数
//复数与整数的+-*/
const Complex operator+(int rhs)
{
return Complex(mReal + rhs,mImage);
}
const Complex operator-(int rhs)
{
return Complex(mReal - rhs,mImage);
}
const Complex operator*(int rhs)
{
return Complex(mReal * rhs,mImage * rhs);
}
const Complex operator/(int rhs)
{
return Complex(mReal / rhs,mImage / rhs);
}
private:
int mReal;
int mImage;
//复数与复数的+-*/
friend const Complex operator+(const Complex&,const Complex&);
friend const Complex operator-(const Complex&,const Complex&);
friend const Complex operator*(const Complex&,const Complex&);
friend const Complex operator/(const Complex&,const Complex&);
//重载输出流运算符
friend ostream& operator<<(ostream&,con