我为我的模板类编写了一个运算符<<:
template<class T>
std::ostream& operator<<(std::ostream &strm, const MyClass<T> &obj)
当我写作时
cout << myClassInstance << endl;
这编译并运行,但我的 Eclipse CDT 说:
Invalid overload of 'endl'
为什么会这样告诉我?
(我在 Win7 64bit 上使用 Eclipse CDT Kepler 和 Cygwin gcc)
最佳答案
我也遇到了这个错误。
//print the value
cout << rt->element << endl;
一个简单的改变:
//print the value
cout << rt->element;
cout << endl;
为我消除了错误。 C++ 新手,但您似乎还需要为 myClassInstance 重载 <<。如果你想用原来的方法。
关于c++ - Eclipse 提示 : "Invalid overload of ' endl'"- but code does compile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17674598/