vectors and push_back
Ok, lets say I have a vector
vector<MyClass> myVec;
When I call:
myVec.push_back(Object); //assume Object is of type MyClass
is Object passed by reference or is a copy of Object placed in the vector?
digital radiation
[edited by - +AA_970+ on November 6, 2002 3:01:58 PM]
[edited by - Stoffel on November 6, 2002 4:24:19 PM]
That''s why you normally should use a vector of (smart) pointers if you''re going to use it with objects.
It places a copy of the object in the vector--it''s the only exception-safe way to do it. Overload your copy constructor to output a message and you will see it called when you push_back.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement