Is “rebinding” references in C++ like this legal?

前端 未结 3 1812
天涯浪人
天涯浪人 2020-12-13 09:13

Is the following legal in C++?

As far as I can tell, Reference has a trivial destructor, so it should be legal.
But I thought references can\'t be r

3条回答
  •  借酒劲吻你
    2020-12-13 09:37

    You aren't rebinding a reference, you're creating a new object in the memory of another one with a placement new. Since the destructor of the old object was never run I think this would be undefined behavior.

提交回复
热议问题