MFC中三個重要的巨集
阿新 • • 發佈:2019-02-19
DELCARE_DYNAMIC(class) IMPLEMENT_DYNAMIC(class, classBase)
DELCARE_DYNAMIC(class) 主要用於宣告CRunTimeClass結構,和獲取CRunTimeClass指標,完成RTTI
#define DECLARE_DYNAMIC(className)\
public:\
static CRuntimeClass class##className;\
virtual CRuntimeClass *GetRuntimeClass() const;
DECLARE_DYNCREATE(class) IMPLEMENT_DYNCREATE(class, classBase)
DECLARE_DYNCREATE(class_name)包含DECLARE_DYNAMIC
#define DECLARE_DYNCREATE(class_name)\
DECLARE_DYNAMIC(class_name)\
static CObject* PASCAL CreateObject();
DECLARE_SERIAL(class_name) IMPLEMENT_SERIAL(class_name, classBase, wSchema)
包含DECLARE_DYNCREATE(class_name)
抽象類中IMPLEMENT_SERIAL巨集必須重定義
三個巨集使得分別具有三個等級的效能:
1.基本機能以及物件診斷(可以使用afxDump輸出診斷資訊),以及Run Time Type Information(RTTI),IsKindOf()就是RTTI的化身;
2. 動態建立(Dynamic Creation)
3. 檔案讀寫(Serialization)