In C struct's, I'm guaranteed that:
struct Foo { ... };
struct Bar {
Foo foo;
...
}
Bar bar;
assert(&bar == &(bar.foo));
Now, in C++, if I have:
class Foo { ... };
class Bar: public Foo, public Other crap ... {
...
}
Bar bar;
assert(&bar == (Foo*) (&bar)); // is this guaranteed?
If so, can you give me a reference (like "The C++ Programming Language, page xyz")?
Thanks!
There is no guarantee. From the C++03 standard (10/3, class.derived):
The order in which the base class subobjects are allocated in the most derived object (1.8) is unspecified.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With