Is taking the address of a member of an uninitialized object well defined?

前端 未结 2 1248
情话喂你
情话喂你 2021-01-13 11:31

Consider the following example. When bar is constructed, it gives it\'s base type (foo) constructor the address of my_member.y where <

2条回答
  •  北海茫月
    2021-01-13 12:18

    Yes you are allowed to pass &my_member.y to foo's constructor, and even copy the pointer - which you do with x(p_x).

    The behaviour on dereferencing that pointer though in foo's constructor is undefined. (But you don't do that.)

提交回复
热议问题