c++ - How to deallocate an element in a vector of pointers? -


so have vector of pointers so:

vector<example*> ve; 

i fill vector pointers this

example* e = new example(); ve.push_back(e) 

but when want remove them, how assure deallocated? enough?

ve.erase(ve.begin() + 1) delete ve[1] 

you have other way round, of course:

delete ve[1]; ve.erase(ve.begin() + 1); 

however, it's vastly more preferable use smart pointers (such std::unique_ptr) instead of raw pointers when expressing ownership.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -