如下程序:
#include "stdio.h" class Base { public: Base() { Init(); } virtual void Init() { printf("Base Init\n"); } void func() { printf("Base func\n"); } }; class Derived: public Base { public: virtual void Init() { printf("Derived Init\n"); } void func() { printf("Derived func\n"); } }; int main() { Derived d; ((Base *)&d)->func(); return 0; }
该程序的执行结果