Skip to main content
GameDev.net gamedev.net
🔒 Locked

STL vector

Started by Silex Dec 3, 2005 at 6:32 PM 4 replies 450+ views
Original Post
Silex
Silex
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]
SiCrane
SiCrane
std::vector will call the assignment operator and copy constructor.
Silex
Silex
[edit] Does the erase method, though?
SiCrane
SiCrane
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.
SiCrane
SiCrane
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.
Silex
Silex
Thanks!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.