Usage of “this” in destructor

前端 未结 2 1522
慢半拍i
慢半拍i 2020-12-11 01:57

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

相关标签:
2条回答
  • 2020-12-11 02:07

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

    0 讨论(0)
  • 2020-12-11 02:22

    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.

    0 讨论(0)
提交回复
热议问题