错误提示,不明白。
# include<iostream>using namespace std;
class Complex{
double real,imag;
public:
Complex(double r=0,double i=0):real(r),iamg(i){}
double Real(){
return Complex::real;
}
double Imag(){
return Complex::imag;
}
Complex operator +(Complex &c);
Complex operator +(double d);
Complex operator =(Complex c);
};
Complex Complex::operator +(Complex &c){
Complex temp;
temp.real=real+c.real;
temp.imag=image+c.imag;
return temp;
}
Complex Complex::operator +(double d){
Complex temp;
temp.real=real+d;
temp.imag=imag;
return temp;
}
Complex Complex::operator =(Complex c){
real=c.real;
iamg=c.imag;
return *this;
}
void main(){
Complex c1(3,4),c2(5,6),c3(0,0);
cout<<"c1 = "<<c1.Real()<<" + j"<<c1.Imag()<<endl;
cout<<"c2 = "<<c2.Real()<<" + j"<<c2.Imag()<<endl;
c3=c1+c2;
cout<<"c3 = "<<c3.Real()<<" + j"<<c3.Imag()<<endl;
cout<<"c3+6.5 = "<<c3.Real()<<" + j"<<c3.Imag()<<endl
}
编译后:
--------------------Configuration: OperateCoverObject - Win32 Debug--------------------
Compiling...
PluralClass.cpp
F:\vc++\vc++程序\MyObject\OperateCoverObject\PluralClass.cpp(7) : error C2614: 'Complex' : illegal member initialization: 'iamg' is not a base or member
F:\vc++\vc++程序\MyObject\OperateCoverObject\PluralClass.cpp(22) : error C2065: 'image' : undeclared identifier
F:\vc++\vc++程序\MyObject\OperateCoverObject\PluralClass.cpp(33) : error C2065: 'iamg' : undeclared identifier
F:\vc++\vc++程序\MyObject\OperateCoverObject\PluralClass.cpp(46) : error C2143: syntax error : missing ';' before '}'
执行 cl.exe 时出错.
OperateCoverObject.exe - 1 error(s), 0 warning(s)