友元:解决运算符重载顺序问题
目录
运算符重载
代码举例:复数类的加号重载
#include<iostream>
#include<cmath>
using namespace std;
class complex{
private:
int real,imag;
public:
complex(int r=0,int i=0):real(r),imag(i){
}
int realshow(){
return real;}
int imagshow(){
return imag;}
void printc(){
cout<<real<<'+'<<imag<<'i'<<endl;
}
complex operator+(const complex &);
friend complex operator+(int);
complex Sum(const complex &);
complex operator+(int);
bool operator==(complex);
complex operator++();
complex operator++(int);
~complex(){
};
};
complex complex::operator++(){
this->real+=1;
return *this;
}
complex complex::operator++(int){
this->real+=1;
return *