gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 21:39:30 26 4
gpt4 key购买 nike

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

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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com