Originally Posted by Paul McKenzie
Do you see the problem with this line of code? The problem is that you're modifying the vector that you're reading from. The push_back() takes a reference to the item to add. You are giving a reference, but at the same time, you're changing the container that gives you that reference. Therefore the behaviour is undefined.
For example, what if adding an item causes a reallocation to occur? That reference you passed is no longer valid, and I have a suspicion this is the reason why your code didn't work -- a reallocation was done, the reference is refering to junk, and you get a blank that is added.
So the bottom line is that there is no such thing as a "self-appending vector" in the sense that you can't call push_back() with a reference to one of the vector's items.