一行代码胜过千言万语。
#include <iostream>
#include <type_traits>
using namespace std;
struct A
{
int a;
};
struct B : A
{
int b;
};
int main()
{
cout << is_standard_layout<B>::value << endl; // output false! WHY?
return 0;
}
B b; cout << (reinterpret_cast<int*> (&b) == (&b.b)) << endl;
输出 false。 - Pete Kirkham&b == &b.a
应该输出true
。 - Matthieu M.