Sachin
Sachin

Reputation: 21911

Declaring refrences /objects in Destructor of a class

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 //
   }
}

Upvotes: 1

Views: 107

Answers (2)

Arsen Mkrtchyan
Arsen Mkrtchyan

Reputation: 50752

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?

Upvotes: 0

Roger Pate
Roger Pate

Reputation:

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.

Upvotes: 5

Related Questions