tags:

views:

62

answers:

2

Does it make any sense of declaring objects or refrences in a destructor of a class in C++?

I mean

class A
{
   A()
   {
   }

  ~A()
   {
      //Declaring refrences or objects  here //
   }
}
A: 

you can declare any type of variable if you need it, but you should delete it properly like in the other cases. what is the case?

ArsenMkrt
+5  A: 

If you need local variables in your dtor, then use them. There is no special restriction; the body of a dtor is treated like the body of any function. If you don't need them, then it wouldn't make sense to declare them.

Roger Pate