Sign in to follow this  
Silex

STL vector

Recommended Posts

Silex    140
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]

Share this post


Link to post
Share on other sites
SiCrane    11839
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.

Share this post


Link to post
Share on other sites
SiCrane    11839
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this