RUNTIME_CLASS()是一个宏定义,定义如下:
#define RUNTIME_CLASS(class_name) ((CRuntimeClass*)(&class_name::class##class_name))
是得到类名为class_name中的CRuntimeClass静态成员的指针。
#define RUNTIME_CLASS(class_name) ((CRuntimeClass*)(&class_name::class##class_name))
是得到类名为class_name中的CRuntimeClass静态成员的指针。
class MyClass : CObject
{
public:
int x,y;
CRuntimeClass classMyClass;
MyClass();
~MyClass();
};RUNTIME_CLASS(CMyClass)的值为 &classMyClass;
它是在MFC中定义的,当然在C++中不会学到。
它的用法是
RUNTIME_CLASS( class_name )
返回参数所指定类的CRuntimeClass结构指针。
只有从CObject派生来,并且在类定义中使用用DECLARE_DYNAMIC, DECLARE_DYNCREATE, 或者DECLARE_SERIAL的类才可以使用RUNTIME_CLASSRUNTIME_CLASS returns a pointer to a CRuntimeClass structure for the class specified by class_name. Only CObject-derived classes declared with DECLARE_DYNAMIC, DECLARE_DYNCREATE, or DECLARE_SERIAL will return pointers to a CRuntimeClass structure.举例如下:
// example for RUNTIME_CLASS
CRuntimeClass* prt = RUNTIME_CLASS( CAge );