> I made a Stack structure, as an exercise on templates.
Stack ll;
Is this used irl? : "ll << o" to push an object pointer to the end of
the list and "ll >> &o" to push it off and save the address in &o or
s'thing similar. I mean the usage of the <</>> operators..
We need to learn good style, I was wodnering if this is..good style..or
just a newbie's obsession with operator overloading.
Be very careful when overloading operators. They are a powerful feature
and are easily over/misused. In particular, the use of operators << and
with streams allows a simple way to chain operations. Since
pushing values in chain on a stack is quite rare, I would believe this
is not a good idea.
When overloading operators, think about what a programmer expects when
using an operator. The operator + represents adding two things together
and operator () represents a function call. Operator <<, in the context
of a stream, means "put into". Your version would slightly change that
meaning and I don't think the synctactic change makes enough difference
to justify that change.
Jonathan