Hi,
I do have doubt regading use of delete p . In most of the scenarios we call delete inside the destructor if we would have called something int *p = new int (10); but as per below code snippet (original code of delete p)
it already invoke the destructor then call the operator delete then why we should call delete p inside the
destructor.

// Original code: delete a;
if (a != NULL) {
  a->~A();
  operator delete(a);
}

code snippet where we call the delete a inside destructor

class B
{
int *a;
public:
B()
{
a=new int(90);

}
~B()
{
cout<<"B's destructor";
delete a;

}
void dial()
{

cout<<"dial the tone";
}
}; 

~Mohan

Sorry if I might be wrong but what I have done is to create a ::destroy() function then I can choose to destroy and handle the deallocation of variables when I choose to do so. Preventing double deletion when the program exits and calls the destructor.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.