短い例では奇妙な結果が出力されます!
#include <iostream>
using namespace std;
struct A { int a; };
struct B { int b; };
struct C : A, B
{
int c;
};
int main()
{
C* c = new C;
B* b = c;
cout << "The address of b is 0x" << hex << b << endl;
cout << "The address of c is 0x" << hex << c << endl;
if (b == c)
{
cout << "b is equal to c" << endl;
}
else
{
cout << "b is not equal to c" << endl;
}
}
出力が次のようになることは、私にとって非常に驚くべきことです。
The address of b is 0x003E9A9C
The address of c is 0x003E9A98
b is equal to c
私が不思議に思うのは:
0x003E9A9C は 0x003E9A98 と等しくありませんが、出力は "b is equal to c" です