因为项目需要,在设计几个类继承关系时,发现如下奇特现象,后来查阅资料发现与C++继承时,this指针的传递,继承顺序,虚函数表有关,未深究【以为已找到针对项目的合适方案】。
项目中的异常抽象出来如下:【图片代表我的心】【图片看不清把页面放大即可,下方有代码】
#include <stdio.h>
#define __WIN32__
#ifdef __WIN32__
#define POINTER int
#elif defined __LINUX__
#define POINTER long
#endif
class ShiYe
{
public:
void Run()
{
printf("ShiYe::Run\t this=0x%08X\n",(POINTER)this);
}
virtual void Null()=0;
};
class AiQing:public ShiYe
{
public:
void Start()
{
printf("AiQing::Start\t this=0x%08X\n",(POINTER)this);
Run();
}
virtual void Null(){};
};
int main(int argc, char* argv[])
{
AiQing *aq=new AiQing();
aq->Start();
delete aq;
getchar();
return 0;
}