永发信息网

DECLARE_DYNAMIC(CListeningSocket);哪位兄弟知道此句中“DECLARE_DYNAMIC”的作用和用法?

答案:2  悬赏:0  手机版
解决时间 2021-11-13 21:51
  • 提问者网友:太高姿态
  • 2021-11-13 01:17
DECLARE_DYNAMIC(CListeningSocket);哪位兄弟知道此句中“DECLARE_DYNAMIC”的作用和用法?
最佳答案
  • 五星知识达人网友:迟山
  • 2021-11-13 01:39
DECLARE_DYNAMIC()相当于以下两句
CRuntimeClass * crt;
CRuntimeClass * GetCRuntimeClass();
//类似于这样的,具体是什么记不清了

IMPLEMENT_DYNAMIC()是对这两个声明的定义;

VC 如果要支持运行时类型识别,必须使用这两个宏,
因为 MFC 不自动支持 RTTI (运行时类型识别) 机制....
全部回答
  • 1楼网友:一秋
  • 2021-11-13 02:51
DECLARE_DYNAMIC( class_name )

Parameters

class_name

The actual name of the class (not enclosed in quotation marks).

Remarks

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.

MSDN的解释。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯