关于指针类型强转,故意没分的,呵呵
程序代码:
#include "stdafx.h" #include <iostream> class A { public: A() {} virtual ~A() {} public: virtual void Display() { std::cout << "A" << std::endl; } }; class B : public A { public: B() : A() {} virtual ~B() {} public: virtual void Display() { std::cout << "B" << std::endl; } }; int main() { B* b = new B(); b->Display(); UINT32 p = (UINT32)b; A* a = (A*)p; a->Display(); char ch; std::cin >> ch; }
我以为会是BA,结果输出是BB
我大概模模糊糊知道为什么,求专家详解
[ 本帖最后由 peach5460 于 2013-4-8 21:36 编辑 ]