我是 C++ 新手,我用 MS Visual C++ 创建了一个单文档界面应用程序。当我编译它时,在名为 Day10 SDIDOC.h 的头文件中出现了一些错误,如下所示
error C2143: syntax error : missing ';' before '*'
error C2501: 'CLine' : missing storage-class or type specifiers
error C2501: 'GetLine' : missing storage-class or type specifiers
error C2143: syntax error : missing ';' before '*'
error C2501: 'CLine' : missing storage-class or type specifiers
error C2501: 'AddLine' : missing storage-class or type specifiers
我的文件是
第 10 天 SDIDOC.h
public:
CLine * GetLine(int nIndex);
int GetLineCount();
CLine * AddLine(CPoint ptFrom,CPoint ptTo);
CObArray m_oaLines;
virtual ~CDay10SDIDoc();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
这些 GetLine() 和 AddLine() 方法在 Day10 SDIDOC.cpp 中像这样实现
Day10 SDIDOC.cpp
CLine * CDay10SDIDoc::AddLine(CPoint ptFrom, CPoint ptTo)
{
//create a new CLine Object
CLine *pLine = new CLine(ptFrom,ptTo);
try
{
//Add the new line to the object array
m_oaLines.Add(pLine);
//Mark the document as dirty(unsaved)
SetModifiedFlag();
}
//Did we run into a memory exception ?
catch(CMemoryException* perr)
{
//Display a message for the user,giving the bad new
AfxMessageBox("Out of Memory",MB_ICONSTOP|MB_OK);
//Did we create a line object?
if(pLine)
{
//Delete it
delete pLine;
pLine = NULL;
}
//delete the exception object
perr->Delete();
}
return pLine;
}
和 GetLine 方法
CLine * CDay10SDIDoc::GetLine(int nIndex)
{
return (CLine*) m_oaLines[nIndex];
}
我不明白有什么问题。请给我一个解决方案。谢谢...