C++ Logo

std-discussion

Advanced search

Re: `from_promise` and base classes

From: Matthew House <mattlloydhouse_at_[hidden]>
Date: Sun, 25 Dec 2022 23:23:11 -0500
On Sun, Dec 25, 2022 at 9:42 PM Jason McKesson via Std-Discussion
<std-discussion_at_[hidden]> wrote:
> OK, but... a reference to a base class subobject is also a reference
> to the most derived-object, right?

I don't think this is correct. A standard-layout class object is
pointer-interconvertible with its base class subobjects (6.8.4
[basic.compound] para. 4), so they share the same address. But a
reference to a base class subobject is logically distinct from a
reference to the most derived object, and in general one cannot be
used where the other is expected.

Received on 2022-12-26 04:23:23