指针值不同,但它们相等。为什么?[转]

原文

#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;
	}
}

原因:不同类型的指针会进行隐式类型转换。

指针值不同,但它们相等。为什么?[转]