Suppose there is a destructor for an object as:
anObject::~anObject()
{
_functionCalledfromDestructor=1; //this sets the flag = 1
functionCall(); //this function does something different than usual
//on seeing the flag
}
My question:
Is this style/method of coding in the destructor a good practice?
“Hidden channels” like this are always a bad idea. The behavior of a function shouldn’t depend on invisible state. You could give the function an argument, and then pass one value in the destructor and another value everywhere else. You could use a default value for the more common case, if you wish.