gipsy boy said:
I made a Stack structure, as an exercise on templates.
Stack ll;
Is this used irl? : "ll << o" to push
Not commonly, but there's no apparently overwhelming reason not to. It
has the advantage that (as with the streaming operators) << associates
the right way so that you can make ll << a << b do what you expect.
Questions to ask yourself is: is this usage of << consistent with a
user's "intuitive" understanding of how it's used elsewhere? will the
paired operator >> also be consistent? is there an alternative operator
which would do as well or better? will the rules of operator priority
and association work as the user expects?
an object pointer to the end of the list
But are you sure you mean "pointer" there? Is 'o' a pointer or an
object? Pushing (a copy of) the thing itself is OK; pushing a pointer to
it is asking for trouble.
and "ll >> &o" to push
"pop"
it off and
Here's the problem: that innocent word "and". It turns out that there
are problems with exception safety if you try to write a function which
copies the top element of the stack _and_ removes it in the same
operation.
http://www.awprofessional.com/content/downloads/meyerscddemo/DEMO/MAGAZIN
E/SU_FRAME.HTM
http://www.awprofessional.com/content/downloads/meyerscddemo/DEMO/MAGAZIN
E/CA_FRAME.HTM
http://www.gotw.ca/gotw/008.htm
Bottom line: you can't simultaneously have a robust container _and_ give
save the address in &o or s'thing similar.
I don't like the look of that & or the word "address". What actually
happens to 'o' here?
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.
Look how std::stack does it. They use push(o) to push an item, top() to
get a reference to the top item, pop() to lose the top item.