Eclipse complains: "Invalid overload of 'endl'" - but code does compile

einpoklum picture einpoklum · Jul 16, 2013 · Viewed 17.8k times · Source

I've written an operator<< for my templated class:

template<class T>
std::ostream& operator<<(std::ostream &strm, const MyClass<T> &obj)

and when I write

cout << myClassInstance << endl;

this compiles and runs, but my Eclipse CDT says:

Invalid overload of 'endl'

Why does it tell me that?

(I use Eclipse CDT Kepler on Win7 64bit with Cygwin gcc)

Answer

frmdstryr picture frmdstryr · Sep 17, 2013

I was getting this error as well.

//print the value
cout << rt->element << endl;

A simple change to:

//print the value
cout << rt->element;
cout << endl;

removed the error for me. New to C++, but it seems like you also need to overload << for myClassInstance. If you want to use the original method.