我在此代码中有七个错误,其中包含运算符重载问题,我尝试对>>和<<进行运算符重载,但它不起作用
#include<iostream>
using namespace std;
class complex
{
private:
double re,im;
public:
complex(double a=0.0,double b=0.0)
{re=a;im=b;}
friend istream& operator>>(istream&,complex&);
friend ostream& operator<<(ostream&,complex&);
};
istream& operator>>(istream& s,complex& cc2)
{
cout<<"Enter real part:";
s>>cc2.re;
cout<<"Enter imaginary part:";
s>>cc2.im;
return s;
}
ostream& operator<<(ostream& t,complex& cc2)
{
t<<"The real part="<<cc2.re<<endl;
t<<"The imaginary part="<<cc2.im<<endl;
return t;
}
int main()
{
complex c1,c2(2.4,3.8);
cin>>c1;
cout<<c1;
cout<<c2;
return 0;
}
与在这里工作的GNU / Linux中g++ 4.9.2
,clang++-4.7
和clang++-4.6
。似乎是编译器错误。
您可以尝试更新到VC ++的最新版本。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句