Explain, please, me next things.
#include <iostream>
#include <set>
int main() {
std::set<int>* a = new std::set<int>;
a->insert(2);
a->insert(5);
for ( std::set<int>::iterator it = a->begin(); it != a->end(); it++ ) {
std::cout << *it << std::endl;
}
std::cout << "Deleting a....." << std::endl;
delete a;
for ( std::set<int>::iterator it = a->begin(); it != a->end(); it++ ) {
std::cout << *it << std::endl;
}
return 0;
}
$ g++ test6.cpp && a
2
5
Deleting a.....
2
5
3544585
- Does it make any sense to use operator new creating std::set? As I read in manuals, std::set has its own Allocator object, which is responsible for dynamic memory allocating using operator new. But interesting to know experienced members point of view.
- Why after deallocating memory using delete a members of std::set are still avaliable and have values 2 and 5 like before delete a. And what is the right way to delete member a. Thanks.