Hello all,
I have a question about deleting objects(the objects are stored in a vector)
I Fill the vector as following:
[code=c]
servObj.push_ba ck(new CGame(serversh, game_id)); (1)
[/code]
Since I am calling new, I need to call delete somewhere else in the program.
If I try to delete the first object that was stored in servObj like this:
[code=c]
delete &(servObj.at(0) );
[/code]
And try to erase the first element after that I get segmentation fault(makes sense).
Now my question is, if I just erase the first element, will it cleanly destroy the object that was stored in the first element?
So:
[code=c]
servObj.erase(i tservObj);
[/code]
here itservObj is a vector::iterato r. Will this deallocate the memory properly?
I havnt been coding in C++ for that long(read: never had to bother with memory management) so I would appreciate anyone pushing me in the right direction here.
Thanks in advance
I have a question about deleting objects(the objects are stored in a vector)
I Fill the vector as following:
[code=c]
servObj.push_ba ck(new CGame(serversh, game_id)); (1)
[/code]
Since I am calling new, I need to call delete somewhere else in the program.
If I try to delete the first object that was stored in servObj like this:
[code=c]
delete &(servObj.at(0) );
[/code]
And try to erase the first element after that I get segmentation fault(makes sense).
Now my question is, if I just erase the first element, will it cleanly destroy the object that was stored in the first element?
So:
[code=c]
servObj.erase(i tservObj);
[/code]
here itservObj is a vector::iterato r. Will this deallocate the memory properly?
I havnt been coding in C++ for that long(read: never had to bother with memory management) so I would appreciate anyone pushing me in the right direction here.
Thanks in advance
Comment