运行时类信息机制
// MFCDynimic.cpp : Defines the entry point for the console application.
//
/*
运行时类信息机制:在程序运行过程中,可以判断类对象的相关类的信息以及继承派生类。
*/
#include "stdafx.h"
#include "MFCDynimic.h"
class CAnimal:public CObject
{
DECLARE_DYNAMIC(CAnimal);
};
IMPLEMENT_DYNAMIC(CAnimal,CObject);
class CDog:public CAnimal
{
DECLARE_DYNAMIC(CDog);
};
IMPLEMENT_DYNAMIC(CDog,CAnimal);
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
CDog yellowdog;
if (yellowdog.IsKindOf(RUNTIME_CLASS(CObject)))
{
printf("yellowdog is CObject!n");
}
else
{
printf("yellowdog isn''t CObject!n");
}
return 0;
}