[SOLVED]Questions re: memory management

Hey all,

I have a simple pair class (never got around to implementing SGI STL), where the contained objects are assigned by value. It goes something like this:

1
2
3
4
5
6
7
template<typename T1, typename T2> class Pair
{
   public:
      T1 first;
      T2 second;
      Pair(T1 ob1,T2 ob2):first(ob1),second(ob2){}
}


My questions are:
* In the destructor to Pair, is it necessary for me to delete first and second? If yes, should I do it by calling delete &first; delete &second?

* Assuming that I do NOT have to call delete on first and second, is there anything I should know if I try to delete a pointer to a Pair?

Thanks in advance!
Last edited on
No. Since they are objects instead of pointers to objects, their respective destructors (provided they have one) will be called after Pair's destructor.

Deleting a Pair is safe, as far as I can tell.
Last edited on
groovy. Thank you!
Topic archived. No new replies allowed.