Boost logo

Boost :

Subject: Re: [boost] Question about the weak_ptr constructor with lock() call
From: Peter Dimov (lists_at_[hidden])
Date: 2016-04-20 14:00:45

He-Jie Shih wrote:
> Hi all,
> I have question about this line:
> 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.

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.

Boost list run by bdawes at, gregod at, cpdaniel at, john at