我在看侯老师写的<<深入浅出MFC>>的仿真IMPLENET_DYNAMIC时,在MFC.h里有定义:
#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,base_class_name,0xFFFF,NULL)
而在MFC.CPP里调用已定义的宏:
IMPLEMENT_DYNAMIC(CCmdTarget,CObject)
IMPLEMENT_DYNAMIC(CWinThread,CCmdTarget)
IMPLEMENT_DYNAMIC(CWinApp,CWinThread)
IMPLEMENT_DYNAMIC(CWnd,CCmdTarget)
IMPLEMENT_DYNAMIC(CFrameWnd,CWnd)
IMPLEMENT_DYNAMIC(CDocument,CCmdTarget)
IMPLEMENT_DYNAMIC(CView,CWnd)
出现一连串的ERROR:
error C2065: 'class_name' : undeclared identifier
error C2653: 'class_name' : is not a class or namespace name
error C2065: 'classclass_name' : undeclared identifier
error C2275: 'CCmdTarget::CObject' : illegal use of this type as an expression
error C2440: 'initializing' : cannot convert from 'int' to 'struct CRuntimeClass *'
.......(这是第一个宏出现的,接下的大致上差不多了)
定义的宏没有错啊,class_name作为宏的参数,为什么成了没有定义的东西呢,
更奇怪的是出现了这个东西:CCmdTarget::CObject ,我真不知编译器是怎么搞出来的......百思不得其解,忘告知,谢谢

解决方案 »

  1.   

    简单看了一下:
    1,表头有没有处理;
    2,static 成员有没有初始化;
    3,CCmdTarget::CObject 我看是你的RUNTIME_CLASS宏定义中的指向可能有问题。
      

  2.   

    1.已经包含了DELARE_DYNAMIC的声明头文件
    2.CObject的CRuntimeClass成员不是用那对宏来声明和定义的,是单独处理的.(因为书上是这么写的)
    3.static 成员初始化了.我觉得好像都没问题,我把IMPLEMENT_DYNAMIC宏的代码拷到引用处,然后用实参代替形参,最后虽然出错了,但是可以理解的错误码,不是上面那种莫明其妙的东西,我觉得是不是其它地方有问题啊,不是这里??