类别型录网与 CruntimeClass
若要达到 RTTI 的能力,类库的设计者一定要在类构建时,记录必要的信息,以建立型录。型
录中的信息,最好以链表(linked list)方式连接,将来方便比较。
这份“类别型录”的链表元素将以 CruntimeClass 描述之,这个结构中至少应该有类的名称,
链表的 Next 指针和 First 指针。由于 First 指针属于全局变量,所以它应该以 Static 修饰。
Struct CruntimeClass
{
//Attributes
LRCSTR m_lpnzClassName;
Int m_nObjectSize;
UINT m_wSchema; //schema number of the loaded class
CObject *(PASCAL * m_pfnCreateObject)();//NULL=>abstract class
CRuntimeClass *m_pBaseClass;
//CruntimeClass objects linked together in the simple list
static CRuntimeClass *pFirstClass;
CRuntimeClass * m_pNextClass;
评论1