Question about the weak_ptr constructor with lock() call

Hi all, I have question about this line: https://github.com/boostorg/smart_ptr/blob/develop/include/boost/smart_ptr/w... I still can't understand the sentence: // r.px may already have been invalidated. The px(r.px) // conversion may require access to *r.px (virtual inheritance). The px is just a scalar. Why assigning the scalar will require the de-reference operator? The comment says it's in virtual inheritance, but I still have not idea about it. Thanks, Jerry

He-Jie Shih wrote:
When a class Y derives virtually from X, Y contains a hidden pointer of type X* to its X base (because the offset of the X subobject is not constant). When you assign Y* to X*, the compiler reads the hidden pointer of the Y object. If the Y object is invalid, this usually crashes.
participants (3)
-
Andrey Semashev
-
He-Jie Shih
-
Peter Dimov