我是C++的新手,我用MS Visual C++创建了一个单文档界面应用程序。 当我编译它,如下错误C2143:语法错误:缺少';'在Visual C++的'*'之前
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
我的文件
第十天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(都发生在所谓的第十天SDIDOC.h头文件中的一些错误)和AddLine()方法在Day10中实现此类功能SDIDOC.cpp
Day 10 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];
}
我不明白有什么不好。 请给我一个解决方案。 谢谢...
你有没有包含任何包含'CLine'的标题? – chris
使用[clang](http://clang.llvm.org/)并获取更好的错误消息! –