原文

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

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

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

相关文章:

  • 2021-09-27
  • 2022-12-23
  • 2021-12-28
  • 2021-05-06
  • 2022-02-07
  • 2021-09-04
  • 2021-12-05
猜你喜欢
  • 2022-01-22
  • 2021-12-25
  • 2021-07-25
  • 2021-04-06
  • 2021-04-14
  • 2022-01-22
  • 2022-12-23
相关资源
相似解决方案