KAction
KAction

Reputation: 2017

Usage of "this" in destructor

Is it valid to call some function in destructor with this argument? Function does not store pointer, but assume full-functional object.

Upvotes: 15

Views: 7026

Answers (2)

Roee Gavirel
Roee Gavirel

Reputation: 19443

In one word: YES.
It's fully valid to use this in the D`TOR

Upvotes: 4

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272557

this is still valid in the destructor.

However, you need bear in mind that virtual functions no longer work properly as you might expect once the object is being destroyed; see e.g. Never Call Virtual Functions during Construction or Destruction. Essentially, the dynamic type of the object is modified as each destructor completes.

Upvotes: 20

Related Questions