Does destroying and recreating an object make all pointers to this object invalid?

后端 未结 6 1633
我寻月下人不归
我寻月下人不归 2021-01-11 23:46

This is a follow-up to this question. Suppose I have this code:

class Class {
    public virtual method()
    {
        this->~Class();
        new( this          


        
6条回答
  •  孤独总比滥情好
    2021-01-12 00:15

    Creating a new object at the location of a destroyed one does not make any pointers valid again. They may point to a valid new object, but not the object you were originally referencing.

    You should guarantee that all references were removed or somehow marked as invalid before destroying the original object.

    This would be a particularly difficult situation to debug.

提交回复
热议问题