So, I have a pointer vector like:
vector<Example*> ve;
I fill this vector with such pointers
Example* e = new Example(); ve.push_back(e)
But when I want to remove them, how can I assure them of their release? is that enough?
ve.erase(ve.begin() + 1) delete ve[1]
You should do it the other way around, of course:
delete ve[1]; ve.erase(ve.begin() + 1);
However, it is much more preferable to use smart pointers (for example, std::unique_ptr ) instead of raw pointers when expressing ownership.
std::unique_ptr
You need to remove the pointers before erasing the vector:
for (vector<Example *>::iterator it = vec.begin(); it != vec.end(); it++) { delete *it; } vec.clear();
Source: https://habr.com/ru/post/944970/More articles:How to check if a file can be deleted? - javaCalling a method in a model from a layout in Zendframework 2 - model-view-controllerSql Server fill factor for all indexes using tsql - sqlWhy we use TRUE to load a view in CodeIgniter - codeigniterrenaming a file when creating a zip file through the Maven-assembly plugin - mavenHow to use additional arguments passed with a variable file - Robot framework - pythonGet list based on dropdownlist data in asp.net mvc3 - operatorsSmartgit: moving local changes from branch binding - gitWhy can't we call Date () class methods without a new operator - javascriptHow do you unit test form sets in Django? - djangoAll Articles