我有一个不变的头:
typedef class Foo
{
public:
friend ostream& operator<<(ostream&, Foo&);
}*pFoo, **ppFoo;我试图像这样实现操作符:
#include <iostream>
using namespace std;
#include "Foo.h"
ostream& operator<<(ostream& a, Foo& b){
a << endl;
return a;
}这会引发以下错误:
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int (foo.h)
Error 5 error C2805: binary 'operator <<' has too few parameters (foo.h)
Error 2 error C2433: 'ostream' : 'friend' not permitted on data declarations (foo.h)
Error 4 error C2061: syntax error : identifier 'ostream' (foo.h)记住,头部不能被触摸,我能做什么?
发布于 2015-11-01 21:45:43
如果这是整个标题,那么它就坏了。它缺少了#include <ostream>和std::。
既然你不能改变它,你就必须:
<ostream>和using namespace std (您已经做好了)就C++11而言,包括<iostream>实际上已经足够了,碰巧的是,我的编译器也不能用C++03再现您的问题。。但是在C++03中,您可能需要单独使用#include <ostream> (前者不一定包含后者),从所提供的有限信息中我只能猜到这一点。
https://stackoverflow.com/questions/33467562
复制相似问题