12/8 c++ question, how do I overload << in my class so it will handle
endl? ie: myclass << "some string" << endl
I know how to do the "some string" part:
myclass & operator << (const char * s);
what about endl?
Thanks!!
\_ I thought endl was just a regular char* too.
\_ what self-respecting c++ programmer doesn't have a copy of
stroustrup available? it's in there.
\_ Don't know about you, but the stroustrup text blows chunks.
It is nowhere close to being something like K&R. The text
I usually refer to (but no doubt is incomplete, but hey, that's
what you get with a badly designed kludge of a language) is
the Lippman text we used in CS61B. I rarely have to use
anything arcane like overloading operators, and I think
\_ overloading operators is fine
if it's not done stupidly.
C = A + B has a very well-defined
and clear meaning if A, B, C are
square matrices of size N, for
example. Overloading + to do
a matrix multiply would be a
stupid overload.
that most of the OO baggage of C++ is unnecessary. Not only
that, it seems like popular APIs (i.e. kde, mfc)
promote things like OO very inconsistently.
\_ while i agree that c++ is pretty kludgy in many cases,
if you think operator overloading is "arcane", you must
not know c++ very well at all. do you prefer stuff like
a.add(b).multiply(c).divide(d)? and that's just for nice
short variable names. operator overloading is pretty cool, and
even guy steele thinks java will need it as it matures.
\_ uhg, is all berkeley cs lost? (/ (* (+ a b) c) d) ;-)
\_ if you need to do things like add multiply and divide, sure
it makes sense... but how often do you need those
constructs? the Matrix example above was a good example.
\_ endl is a manipulator, not a string constant. In addition to ending
the line, it flushes the buffer. |