大家好,小金来为大家解答以上的问题。
1、DECLARE_DYNAMIC()相当于以下两句CRuntimeClass * crt; CRuntimeClass * GetCRuntimeClass();//类似于这样的,具体是什么记不清了IMPLEMENT_DYNAMIC()是对这两个声明的定义;VC 如果要支持运行时类型识别,必须使用这两个宏。
2、因为 MFC 不自动支持 RTTI (运行时类型识别) 机制....DECLARE_DYNAMIC( class_name )Parametersclass_nameThe actual name of the class (not enclosed in quotation marks).RemarksWhen 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的解释。
本文到此分享完毕,希望对大家有所帮助。