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

重载流插入运算符 出错!

hzz063 发布于 2010-07-04 17:43, 698 次点击
程序代码:
/* CppHead.h 文件*/

#include <iostream.h>

class ibm
{
public:
    ibm(int = 0,int = 0);
    friend ostream & operator+(ostream &a, ibm &);
private:
    int x;
    int y;
};


ibm ::ibm(int a, int b)
{
    x = a; y = b;
}


ostream & operator +( ostream &output, ibm &b)  //重载
{
    output << b.x << "  " << b.y << endl;

    return output;
}

///////////////////////////////////////////////////////

#include "CppHead.h"

int main(void)
{
    ibm t(100, 200);
    cout << t;
return 0;
}
编译的时候提示:E:\练习文件\【C++】\CPP\CPP.CPP(9) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class ibm' (or there is no acceptable conversion)
执行 cl.exe 时出错.

问题怎么解决呀??
2 回复
#2
最近不在2010-07-04 19:10
friend ostream & operator+(ostream &a, ibm &);+改为<<
#3
zisefengye2010-07-04 20:15
恩,楼上说的对。你重载错符号了。
1