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

后端 未结 6 1631
我寻月下人不归
我寻月下人不归 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-11 23:58

    The pointer only knows its address and as soon as you can confirm that the address of the new object is the one the pointer is pointing to, the answer is yes.

    There are some cases where people would believe the address does not change, but in some cases it does change, e.g. when using C's realloc(). But that's another story.

提交回复
热议问题