在C struct中,我保证:
struct Foo { ... };
struct Bar {
Foo foo;
...
}
Bar bar;
assert(&bar == &(bar.foo));
现在,在C++中,如果我有:
class Foo { ... };
class Bar: public Foo, public Other crap ... {
...
}
Bar bar;
assert(&bar == (Foo*) (&bar)); // is this guaranteed?
如果是这样,可以给我引用(例如“C++编程语言,第xyz页”)吗?
谢谢!
最佳答案
没有保证。从C++ 03标准(10/3,class.derived):