Is there any situation in which an object's storage might change during its lifetime?

前端 未结 3 813
我寻月下人不归
我寻月下人不归 2021-01-11 09:42

I\'ve always assumed that an object begins and ends its lifetime in the same memory location, but I\'ve recently come across a scenario where I need to be sure. Specifically

3条回答
  •  青春惊慌失措
    2021-01-11 10:16

    What you are looking for is defined in [intro.object]/1

    [...] An object occupies a region of storage in its period of construction ([class.cdtor]), throughout its lifetime, and in its period of destruction ([class.cdtor]).

    This means the address cannot change as long as you can access it.

提交回复
热议问题