最近在看候杰深入浅出MFC的电子版, 第一章中有模拟Dynamic Create技术的代码,
我用VC++6.0把代码抄进去之后出现如下错误,检查了好久,竟没有发现原因何在。
编译错误:
E:\MY DOCUMENT\MY PROGRAM STUDY\LEARNJJHOURMFCEXPLAIN\CH2\MFCEmulation\MFC.cpp(63) : error C2653: 'bass_class_name' : is not a class or namespace name
E:\MY DOCUMENT\MY PROGRAM STUDY\LEARNJJHOURMFCEXPLAIN\CH2\MFCEmulation\MFC.cpp(63) : error C2065: 'classbass_class_name' : undeclared identifier
E:\MY DOCUMENT\MY PROGRAM STUDY\LEARNJJHOURMFCEXPLAIN\CH2\MFCEmulation\MFC.cpp(63) : error C2440: 'initializing' : cannot convert from 'int *' to 'struct CRuntimeClass *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
相关的结构:
//--------------------------------------------------------------------------------------------*
struct CRuntimeClass
{
//Attributes
LPCSTR m_lpszClassName;
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 simple list
static CRuntimeClass* pFirstClass; //Start of class list
CRuntimeClass* m_pNextClass; //Linked list of registered classes
};
//--------------------------------------------------------------------------------------------*
struct AFX_CLASSINIT
{
AFX_CLASSINIT(CRuntimeClass* pNewClass);
};
相关的宏定义:
//--------------------------------------------------------------------------------------------*
#define RUNTIME_CLASS(class_name) \
(&class_name::class##class_name)
#define DECLARE_DYNAMIC(class_name) \
public: \
static CRuntimeClass class##class_name;\
virtual CRuntimeClass* GetRuntimeClass() const;
#define _IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, pfnNew) \
static char _lpsz##class_name[] = #class_name; \
CRuntimeClass class_name::class##class_name = { \
_lpsz##class_name, sizeof(class_name), wSchema, pfnNew, \
RUNTIME_CLASS(base_class_name), NULL }; \
static AFX_CLASSINIT _init_##class_name(&class_name::class##class_name); \
CRuntimeClass* class_name::GetRuntimeClass() const \
{ return &class_name::class##class_name;} \
#define IMPLEMENT_DYNAMIC(class_name, base_class_name) \
_IMPLEMENT_RUNTIMECLASS(class_name, bass_class_name, 0xFFFF, NULL)
//--------------------------------------------------------------------------------------------*
源代码: