struct B1 { int x; };
struct B2 { int y; };
struct D : B1, B2 { };
int main() {
D d;
cout << (B1*)&d << " " << (B2*)&d << " " << &d;
}
// Typical output:
// 0xbf814ab4 0xbf814ab8 0xbf814ab4
我想到的是,在<代码>B1无成员时,这种抵消可能不存在,因此我检查并 。 (至少就本案而言;不确定标准如何保障这种行为):
struct B1 { };
struct B2 { };
struct D : B1, B2 { };
int main() {
D d;
cout << (B1*)&d << " " << (B2*)&d << " " << &d;
}
// Typical output:
// 0xbf6ad95b 0xbf6ad95b 0xbf6ad95b
但是,sizeof(T)
不能成为0
,因此,<>>>>>>>>>>>>>>>><1>>。
它告诉我,如果一名方案管理员假设<代码>(char*)(B2*)&d-(char*)(B1*)&d=(ptrdiff_t)sizeof(B1)
我的分析是否准确?