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?
const Foo &a, why don't just pass in the pointervoid push(Foo *a)Fooby value, because you would then be adding the address of a localFooobject that is destroyed/dellocated when the function leaves.Foojust contains two private strings and a private int. I was given the header for the method, and have to fill the rest in