我感觉我这个比较正确,呵呵
#include <iostream>using namespace std;
class Complex{
private:
float r,i;
public:
Complex operator +(Complex &b);
Complex();
Complex(float,float);
void show();
};
Complex Complex::operator +(Complex &b){
Complex temp;
temp.r=r+b.r;
temp.i=i+b.i;
return temp;
}
Complex::Complex(){r=0;i=0;}
Complex::Complex(float a, float b){
r=a;i=b;
}
void Complex::show(){
if(i<0)
cout<<r<<"-"<<-i<<endl;
else
cout<<r<<"+"<<i<<endl;
}
int main(){
Complex c1(10,11),c2(12,-13),c3;//编译时这里出错了
c3=c1+c2;
c3.show();
return 0;
}