我最近在写一个矢量画图工具,在文挡类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.
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.
前面添加:
class CLine;
class CPline;
class CCircle;
class CArc;
class CText;
.cpp中 #include "定义上述类的头文件"or:
#include "定义上述类的头文件"
class CDrawDoc : public CDocument
这个问题你在drawdoc.h文件中加入
#include "引用了的那些类的头文件"
就可以啦~~