Take the 2-minute tour ×  I have a vector of pointers to an
object:  vector<Foo*> bar;  In a method, I am given an Foo
object and need to add it to the vector. This is my current
attempt:  void push(const Foo &a){ bar.insert(bar.begin(), a);
I know this doesnt work because a was passed as a reference, but
I can't seem to get the pointer for a to add to bar.  How can I
add a to the vector bar?  share|improve this question I don't
understand the reason why you pass in a reference const Foo &a,
why don't just pass in the pointer void push(Foo *a) –  Krypton
Oct 2 '12 at 4:06 I was having weird results using the actual
Foo objects –  Flynn Oct 2 '12 at 4:08 In that case, the answers
down here should help –  Krypton Oct 2 '12 at 4:10 It would be a
bad idea to merely pass the Foo by value, because you would then
be adding the address of a local Foo object that is
destroyed/dellocated when the function leaves. –  Sion Sheevok
Oct 2 '12 at 4:10 @chris Foo just contains two private strings
and a private int. I was gi