在C結構的,我保證:現在在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「)?
謝謝!
注意到;謝謝。 :-) g ++幾乎讓我相信這是有保證的。 – anon
作爲一個側面說明,該標準對非POD類型的佈局承諾很少 - 基本上只是非靜態數據成員的地址順序未由介入訪問指定符分隔將與聲明順序相匹配(但僅限於相同的「訪問說明符部分」)。 –