我最近在写一个矢量画图工具,在文挡类CDrawDoc中创建了几个管理各类图形元素对象指针的CObArray对象如下:
class CDrawDoc : public CDocument
{

private:
CTypedPtrArray<CObArray,CLine*>m_LineArray;
CTypedPtrArray<CObArray,CPline*>m_PLineArray;
    CTypedPtrArray<CObArray,CCircle*>m_CircleArray;
CTypedPtrArray<CObArray,CArc*>m_ArcArray;
CTypedPtrArray<CObArray,CText*>m_TextArray;
.....后续代码省略.......
}
由于用到了CTypedPtrArray这个类,于是我在StdAf.h中添加了#include <afxtempl.h>这个头文件代码如下:
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers#include <afxwin.h>         // MFC core and standard components
#include <afxtempl.h>
#include <afxext.h>         // MFC extensions
#include <afxdisp.h>        // MFC Automation classes
但是错误仍旧和没添头文件一样,
如下:
Compiling...
DrawDoc.cpp
f:\draw\drawdoc.h(64) : error C2143: syntax error : missing ';' before '<'
f:\draw\drawdoc.h(64) : error C2501: 'CTypedPtrArray' : missing storage-class or type specifiers
f:\draw\drawdoc.h(64) : error C2059: syntax error : '<'
f:\draw\drawdoc.h(64) : error C2238: unexpected token(s) preceding ';'
f:\draw\drawdoc.h(65) : error C2143: syntax error : missing ';' before '<'
f:\draw\drawdoc.h(65) : error C2501: 'CTypedPtrArray' : missing storage-class or type specifiers
f:\draw\drawdoc.h(65) : error C2059: syntax error : '<'
f:\draw\drawdoc.h(65) : error C2238: unexpected token(s) preceding ';'
f:\draw\drawdoc.h(66) : error C2143: syntax error : missing ';' before '<'
f:\draw\drawdoc.h(66) : error C2501: 'CTypedPtrArray' : missing storage-class or type specifiers
f:\draw\drawdoc.h(66) : error C2059: syntax error : '<'
f:\draw\drawdoc.h(66) : error C2238: unexpected token(s) preceding ';'
f:\draw\drawdoc.h(67) : error C2143: syntax error : missing ';' before '<'
f:\draw\drawdoc.h(67) : error C2501: 'CTypedPtrArray' : missing storage-class or type specifiers
f:\draw\drawdoc.h(67) : error C2059: syntax error : '<'
f:\draw\drawdoc.h(67) : error C2238: unexpected token(s) preceding ';'
f:\draw\drawdoc.h(68) : error C2143: syntax error : missing ';' before '<'
f:\draw\drawdoc.h(68) : error C2501: 'CTypedPtrArray' : missing storage-class or type specifiers
f:\draw\drawdoc.h(68) : error C2059: syntax error : '<'
f:\draw\drawdoc.h(68) : error C2238: unexpected token(s) preceding ';'
Error executing cl.exe.

解决方案 »

  1.   

    你的CLine,CCircle,....在什么地方定义的?
      

  2.   

    我自己新建的类,基类是CDraw,CDraw也是我建的基类是CObject!~
      

  3.   

    在class CDrawDoc : public CDocument
    前面添加:
    class CLine;
    class CPline;
    class CCircle;
    class CArc;
    class CText;
    .cpp中 #include "定义上述类的头文件"or:
    #include "定义上述类的头文件"
    class CDrawDoc : public CDocument
      

  4.   

    兄弟,咱们的错误是一样的,你在学陈建春那本书吧?我也是。加我qq咱们有问题一起讨论吧:76952958
    这个问题你在drawdoc.h文件中加入
    #include "引用了的那些类的头文件"
    就可以啦~~