Vector of pointers help

I have a vector of pointers of a parent class, the "draw()" function is overloaded through each derived class. I need to print the vector out using the draw function. the user is supposed to be able to add as many "shapes" as they want, either a square or a triangle, then it is added to the vector using shapeV.push_back(&mySquare); is this the right way to add things to a vector of pointer types? also i get a terrible run time error when i try to call the draw function using shapeV[index]->draw(); Any help? I chose not to past my code because my teacher made us do like 10 header files. Thanks in advance, Derek.
shapeV.push_back(&mySquare); This looks a bit suspicious. If you are trying to add pointers to local variables you will get a problem when the local variable goes out of scope and the vector contains a bunch of invalid pointers. The way to do it is to dynamically allocate the objects with new.
Topic archived. No new replies allowed.