关于C++运算符<<重载问题,程序出现报错
#include<iostream>usingnamespacestd;classComplex{public:Complex(){r=0;i=0;}Complex(in...
#include<iostream>
using namespace std;
class Complex
{
public:
Complex(){r=0;i=0;}
Complex(int a,int b):r(a),i(b){}
Complex operator +(Complex &obj)
{
return Complex(r+obj.r,i+obj.i);
}
friend ostream &operator << (ostream &, Complex &);
private:
int r,i;
};
ostream & operator << (ostream &output, Complex & p)
{
output<<p.r<<"-----"<<p.i<<endl;
return output;
}
void main()
{
Complex a(2,3),b(4,3),c;
c=a+b;
cout<< c;
}
哪里 错了? 展开
using namespace std;
class Complex
{
public:
Complex(){r=0;i=0;}
Complex(int a,int b):r(a),i(b){}
Complex operator +(Complex &obj)
{
return Complex(r+obj.r,i+obj.i);
}
friend ostream &operator << (ostream &, Complex &);
private:
int r,i;
};
ostream & operator << (ostream &output, Complex & p)
{
output<<p.r<<"-----"<<p.i<<endl;
return output;
}
void main()
{
Complex a(2,3),b(4,3),c;
c=a+b;
cout<< c;
}
哪里 错了? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询