【发布时间】:2011-01-11 08:43:31
【问题描述】:
在 C 结构中,我保证:
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++ inheritance base-class object-address