震撼:重载输出运算符,编译时出现链接错误
在一个自定义类中重载输出运算符,具体代码如下:
#include <cstdlib>
#include <iostream>
using namespace std;
class MyString
{
friend ostream& operator < <(ostream&, const MyString&);
friend istream& operator> > (istream&, MyString&);
};
MyString f(MyString a, MyString b)
{
cout < < "in f: " < < a < < ' ' < < b < < ' ' < < '\n '; // <-这一句出现编译错误
}
int main(int argc, char *argv[])
{
system( "PAUSE ");
}
编译出错的语句为:
cout < < "in f: " < < a < < ' ' < < b < < ' ' < < '\n ';
编译错误为:
[Linker error] undefined reference to `operator < <(std::ostream&, MyString const&) '
到底错在了哪里那?请高手指教,谢谢
[解决办法]
你的那个重载的流运算符代码呢?
[解决办法]
下载个Vs6sp6补丁就可以啦