ein*_*ica 22 c++ templates operator-overloading eclipse-cdt
我为我的模板类写了一个运算符<<
template<class T>
std::ostream& operator<<(std::ostream &strm, const MyClass<T> &obj)
Run Code Online (Sandbox Code Playgroud)
当我写作
cout << myClassInstance << endl;
Run Code Online (Sandbox Code Playgroud)
这编译并运行,但我的Eclipse CDT说:
'endl'的重载无效
为什么告诉我这个?
(我在Win7 64bit上使用Eclipse CDT Kepler和Cygwin gcc)
frm*_*ryr 13
I was getting this error as well.
//print the value
cout << rt->element << endl;
Run Code Online (Sandbox Code Playgroud)
A simple change to:
//print the value
cout << rt->element;
cout << endl;
Run Code Online (Sandbox Code Playgroud)
为我删除了错误.C++的新手,但似乎你还需要重载<< for myClassInstance.如果要使用原始方法.
pho*_*oad 11
问题是(据我所知)使用Eclipse的代码分析工具.
如果您愿意,可以通过完全禁用无效重载检查来避免此消息:
然后你会看到错误消失了.
但是,它可能会跳过真正的错误,最好让它保持检查状态,但使用"Customize Selected"按钮更改其严重性级别.
我已将其更改为"警告"而不是"错误".
正如@plasmaHH所说,我认为Eclipse在这种情况下无法正确解析C++.