STL vector

Started by
4 comments, last by Silex 18 years, 4 months ago
Hi, Quick C++ STL question: I'm using a vector container of a class I've written; since it uses dynamic memory, does the vector container need it to have a copy constructor and/or assignment operator for the erase method? I get around the problem for adding objects to it by having explicit load and unload functions that I call after using methods such as push_back, but I'm worried that internally the vector may be copying or assigning objects for erase. Can anyone clarify this? Cheers, Nick [edit] clarifications [Edited by - Silex on December 3, 2005 6:52:25 PM]
Advertisement
std::vector will call the assignment operator and copy constructor.
[edit] Does the erase method, though?
Then try asking your question again. As far as I can tell you're only asking whether or not your class needs to have the copy constructor and assignment operator.
erase() will call the assignment operator if you don't erase only elements at the end. If any elements are left between the erased elements and the end of the vector, they will have the assignment operator called.
Thanks!

This topic is closed to new replies.

Advertisement