c++ - Eclipse 提示 : "Invalid overload of ' endl'"- but code does compile

标签 c++ templates operator-overloading eclipse-cdt

我为我的模板类编写了一个运算符<<:

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/

相关文章:

c++ - 如何建立一个具有cmake文件的c++/c项目?

c++ - C++ 如何选择要使用的运算符重载?

c++ - 模板函数 - 模板是否覆盖普通函数

c++ - 错误 C2676 二进制 '<<' : 'std::ostream' does not define this operator or a conversion to a type acceptable to the predefined operator

c++ - bool 类型的默认构造函数值

c++ - 使用 boost::make_shared 分配 char* 数组

c++ - 类构造函数中的模板和使用(#define)

c++ - 了解 C++ 运算符重载

c++ - 重载赋值运算符与提供隐式构造函数

c++ - FileStore::OpenErr 在内存位置 0x012FED64