MFC星火03_DECLARE_DYNAMIC

一 关于DECLARE_DYNAMIC的英文说明

When deriving a class from CObject, this macro adds the ability to access run-time information about an object’s class.

Add the DECLARE_DYNAMIC macro to the header (.H) module for the class, then include that module in all .CPP modules that need access to objects of this class.

If you use the DECLARE_DYNAMIC and IMPLEMENT_DYNAMIC macros as described, you can then use the RUNTIME_CLASS macro and the CObject::IsKindOf function to determine the class of your objects at run time.

If DECLARE_DYNAMIC is included in the class declaration, then IMPLEMENT_DYNAMIC must be included in the class implementation.

中文综合大意:

对于从CObject派生的类用DECLARE_DYNAMIC 宏可以使对象类有查询运行时信息的能力。

在类的头文件中加入DECLARE_DYNAMIC宏,在实现文件中加入 IMPLEMENT_DYNAMIC,两者配对使用之后就可以用RUNTIME_CLASS  

宏 和CObject::IsKindOf 函数确定对象的运行时类型信息。


二 例子

class CPerson : public CObject 
{
   DECLARE_DYNAMIC( CPerson )

   // other declarations
};
IMPLEMENT_DYNAMIC( CPerson, CObject )
三 内部机制

通过创建一个链表来保存类的信息,DECLARE_DYNAMIC是声明IMPLEMENT_DYNAMIC则是定义。







  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值