Tuesday, August 15, 2006

MFC 的 Dynamic Object Creation

這玩意實在是有點鳥,根據 Programming Windows With MFC 第九章的講法, DECLARE_DYNCREATE(CMyClass) 是個 macro,會被轉成: public: static const AFX_DATA CRuntimeClass classCMyClass; virtual CRuntimeClass *GetRuntimeClass; static CObject *PASCAL CreateObject(); IMPLEMENT_DYNCREATE(CMyClass, CBaseClass) 也是個 macro,其中會把 CreateObject 寫成: CObject *PASCAL CMyClass::CreateObject(){ return new CMyClass; } 最好玩的是,RUNTIME_CLASS() 這個 macro。RUNTIME_CLASS(CMyClass)->CreateObject() 跟 CMyClass *t = new CMyClass(); 是一樣的啊。

No comments:

codeblock