当前位置:C++技术网 > 资讯 > 运行时类信息机制判断类对象

运行时类信息机制判断类对象

更新时间:2015-06-24 13:18:33浏览次数:1+次

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