to hold just the adresses of someClass's objects dynamically allocated. Say I want to get rid of one of those objects. I guess doing just:
1 2 3 4 5 6 7 8 9 10 11 12
vector<someClass *>::iterator it = myVector.begin();
// search for the element I want to erase( )
for(; it !=myVector.end(); it++){
if (it->someMember == someVariable){
// deleting process
myVector.erase(it);
break;
}
}
would erase only the pointer, and the object would generate a memory leak. So, how to make a deep cleaning?
I'm thinking like this:
it ------> a pointer to a vector's element
*it ------> the object being pointed by it ---------> a pointer to someClass object
**it -----> the object being pointed by the pointer being pointed by iterator it
I guess I should write:
delete *it;
just want to make shure.
I'm not finding any good answer through the web. I'd appreciate your help!
Assuming the pointer points to a single instance of someClass:
delete *it ;
Of course if it is pointing to a single instance of someClass, it begs the question: Why not just store the instance directly? (vector<someClass> myVector;)
Thank you. Of course, the reason I'm holding just the adress of someClass objects is that they are more than one and are very "fat" objects (can't find a better word!). They have a lot of members, QWidgets, and so and so...