On Jul 15, 11:05 pm, Joshua Maurice <joshuamaur...@gmail.com> wrote:
On Jul 15, 6:27 am, =D6=F6 Tiib <oot...@hot.ee> wrote:
[...]
To reiterate my question, I don't understand how an object
could exist in non-contiguous storage, but still be
creatable with placement new.
An object doesn't have to always have the same
representation. When you create an object with placement
new, you are creating an object of the most derived type.
If we abstract padding bytes (considering them part of the
object), then an object must consist of a contiguous block
of storage. Once we consider sub-objects (which are objects
too), the issue is less clear. Consider:
struct Base { virtual ~Base(){} int takesSpace; };
struct Derived : virtual Base { int takesSpace; };
struct Further : Derived { int takesSpace; };
If you do sizeof(Derived), you'll get a size which
represents the size of a Derived when it is the most derived
class. If you fiddle around with the addresses in the
Derived base class of Further, however, there's a good
chance that the difference between some of those addresses
if greater than sizeof(Derived)---in some (most?)
implementations, Further::takesSpace, which is not part of
the Derived object, will be placed between Base::takesSpace
and Derived::takesSpace, both part of the derived object.
(If this example doesn't show it, it should be easier to
come up with more complicated ones that do.)
Oh of course, with virtual inheritance. Is that the point of
perfect sense. Still, am I right to think it would be a