I overloaded operator <<
template <Typename T>
UIStream& operator<<(const T);
UIStream my_stream;
my_stream << 10 << " heads";
Works but:
my_stream << endl;
Gives compilation error:
error C2678: binary '<<' : no operator found which takes a left-hand operand of type 'UIStream' (or there is no acceptable conversion)
What is the work around for making my_stream << endl
work?
Best Answer
std::endl
is a function andstd::cout
utilizes it by implementingoperator<<
to take a function pointer with the same signature asstd::endl
.In there, it calls the function, and forwards the return value.
Here is a code example:
Hopefully this gives you a better idea of how these things work.