Does calling a destructor explicitly destroy an object completely?

前端 未结 11 1436
日久生厌
日久生厌 2020-12-03 14:43

If I call a destructor explicitly ( myObject.~Object() ) does this assure me that the object will be appropriately destroyed (calling all child destructors) ?

Ok so

11条回答
  •  情歌与酒
    2020-12-03 15:22

    Yes, a destructor, even when called explicitly, will destroy its subobjects properly.

    As you seem to realize, it's a rare action to do, but perhaps as part of a well tested and documented library it may be useful. But document (and profile) it since even though it's valid and safe, every maintainer (including you) will never feel comfortable with it.

提交回复
热议问题