1.

Is It Possible For A Member Function To Use Delete This?

Answer»

It is possible for a member function to use delete this but on certain conditions which are as follows:

  1.  Ensure that the allocation of this OBJECT is done through new[] operator.
  2. Ensure that the invocation of a member function done on this (current) object will be the last member function.
  3. Ensure that calling of other member functions and data members should not be done after the line of code which includes delete this.
  4. Examination or comparison of this pointer with other pointers and NULL, printing or casting it, MUST be avoided after using the delete this.

The preceding points are applied in the cases where the this pointer BELONGS to the base class in the absence of the VIRTUAL destructor.

It is possible for a member function to use delete this but on certain conditions which are as follows:

The preceding points are applied in the cases where the this pointer belongs to the base class in the absence of the virtual destructor.



Discussion

No Comment Found