注册 登录
编程论坛 C++教室

运算符重载的问题

小爸爸 发布于 2013-12-09 22:56, 449 次点击
#include<iostream>
using namespace std;
class complex
{
private:
    double x,y;
public:
    complex(double a=0,double b=0)
        :x(a),y(b)
    {}
    friend ostream& operator <<(ostream& os,const complex& rhs);
};
ostream& operator <<(ostream& os,const complex& rhs)
{
    os<<rhs.x<<"   "<<rhs.y<<endl;
    return os;
}
int main()
{
    complex p(1,2);
    cout<<p<<endl;
}
2 回复
#2
kevin_012013-12-09 23:25
你是用VC++6.0吧,换一个编译器就没错误了,用code blocks 编译器运行没错

只有本站会员才能查看附件,请 登录
#3
小爸爸2013-12-12 14:59
回复 2楼 kevin_01
谢谢啊
1