How to clean a vector / map?

If I have vector<string*> *vect, or map<pair<string*, int*>, string*> *map,
how to clean all (including the entire object that contains the vector / card)?
(Everything (vector, map, contents, string, ints) is highlighted new)

Is that enough:

delete vect;
delete map;
+3
source share
4 answers

No, you have to go through vector/ map, delete and delete its elements in turn (which, as indicated in @SB, may require a recursive removal of their elements).

( , , , , , , , , .)

, , .

+6

.

vector<boost::shared_ptr<std::string> >* some_vector = new std::vector<boost::shared_ptr<std::string> >;

some_vector->push_back(boost::shared_ptr<std::string>("Hello World !"));

delete some_vector; // This will delete the contained std::string as well
some_vector = NULL;

, . ( ..), , .

"" (delete).

+4

, delete , . , .

, . .

0

, Boost Pointer Container. , , , ( ) .

- , ( ).

, , . , - , , .

0

Source: https://habr.com/ru/post/1750494/


All Articles