我的一段,实际上就是《深入浅出MFC》,我把CStroke类定义从CDoc中分离出来。CStroke.h
class CStroke: public CObject  
{
public:
CStroke(UINT nPenWidth);
DECLARE_SERIAL(CStroke);
virtual ~CStroke();
protected:
CStroke();
protected:
UINT m_nPenWidth;
public:
CArray<CPoint,CPoint> m_pointArray;
BOOL DrawStroke(CDC* pDC);
virtual void Serialize(CArchive& ar);
}
CStroke.cpp#include "StdAfx.h"
#include "sam4_scrib.h"
#include "Stroke.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_SERIAL(CStroke,CObject,1);
CStroke::CStroke()
{}CStroke::~CStroke()
{}CStroke::CStroke(UINT nPenWidth)
{
    m_nPenWidth=nPenWidth;
}
CStroke::Serialize (CArchive &ar){
if(ar.IsStoring()){
ar<<(WORD)m_nPenWidth;
m_pointArray.Serialize(ar);
}
else{
WORD w;
ar>>w;
m_nPenWidth=w;
m_pointArray.Serialize(ar);
}
}
BOOL CStroke::DrawStroke(CDC *pDC){
CPen penStroke;
if(!penStroke.CreatePen(PS_SOLID,m_nPenWidth,RGB(0,0,0)))return FALSE;
CPEN* pOldPen=pDC->SelectObject(&penStroke);
pDC->MoveTo(m_pointArray[0]);
for(int i=0;i<m_pointArray.GetSize();i++){
pDC->LineTo(m_pointArray[i]);
}
pDC->SelectObject(pOldPen);
return TRUE;
}
怎么就是说 :g:\myproj\vc6sample\sam4_scrib\stroke.h(35) : error C2143: syntax error : missing ';' before '<'   就是CArray<CPoint,......有错误还有, m_pointArray,不是数组
高手们指点一下

解决方案 »

  1.   

    老兄,好像stdafx.h 最终包括了afxtempl.h。。没用的,不过谢谢你
      

  2.   

    你最好确认一下stdafx.h中是否已经有了#include <afxtempl.h>
    这个头文件缺省情况下是不包含的
      

  3.   

    下面是没有包含#include <afxtempl.h>时的编译错误提示e:\moderncppdesign\testnew\testnewdlg.h(35) : error C2143: syntax error : missing ';' before '<'
    e:\moderncppdesign\testnew\testnewdlg.h(35) : error C2501: 'CArray' : missing storage-class or type specifiers
    e:\moderncppdesign\testnew\testnewdlg.h(35) : error C2059: syntax error : '<'
    e:\moderncppdesign\testnew\testnewdlg.h(35) : error C2238: unexpected token(s) preceding ';'
      

  4.   

    就是写了#include <afxtempl.h>
    也没用,不过还是谢谢你的热心
      

  5.   

    那就奇怪了,要不把你的源代码发给我?[email protected]
      

  6.   

    CArray<CPoint,CPoint> m_pointArray;
    ---------------------------------------
    1.#include <afxtempl.h>注意是template的templ不是1
    2.修改为CArray<CPoint,&CPoint> m_pointArray
    试试看,我没有帮你测试!