tags:

views:

88

answers:

2

I have a pair pointer let us suppose std::pair< A*, B* >* pointerpair. I allocated it memory and after using the pair i call delete pointerpair.

Will it also call delete A and delete B and will be freeing the memory completely ?

if i only call delete A and delete B but no delete pointerpair then is it a memory leak ?

+5  A: 

no.............

rwong
In STL and Boost, there is a family of classes called smart pointers, which can automatically delete the objects whose pointers are stored in them. However, outside those smart pointer classes, any raw pointers stored in STL / Boost containers are simply treated as pointers. For example, you can define a set of raw pointers to strings. This set will be sorted using the pointer values, not the lexicographical order of the strings (unless you supply your comparison functor).
rwong
+2  A: 

No. It won't do it automatically. You have to delete it explicitly.

Chubsdad