声明了一个返回值为对象指针的member function,可是指针部分好象有问题声明部分:
class CDay10Doc : public CDocument
{
// ……
public:
CLine* AddLine(CPoint ptFrom, CPoint ptTo);
};实现部分:
CLine* CDay10Doc::AddLine(CPoint ptFrom, CPoint ptTo)
{
CLine *pLine = new CLine(ptFrom, ptTo);

try
{
m_oaLines.Add(pLine);
SetModifiedFlag();
}
catch(CMemoryException *perr)
{
AfxMessageBox("Out of memory", MB_ICONSTOP | MB_OK); if(pLine)
{
delete pLine;
pLine = NULL;
}
perr->Delete();
}
return pLine;
}编译器提示的错误为:
e:\vc study\day10\day10doc.h(35) : error C2143: syntax error : missing ';' before '*'
e:\vc study\day10\day10doc.h(35) : error C2501: 'CLine' : missing storage-class or type specifiers
E:\VC Study\Day10\Day10Doc.cpp(88) : error C2501: 'AddLine' : missing storage-class or type specifiers
E:\VC Study\Day10\Day10Doc.cpp(89) : error C2065: 'pLine' : undeclared identifier
E:\VC Study\Day10\Day10Doc.cpp(89) : error C2061: syntax error : identifier 'CLine'
E:\VC Study\Day10\Day10Doc.cpp(92) : error C2143: syntax error : missing ';' before '{'
E:\VC Study\Day10\Day10Doc.cpp(92) : error C2143: syntax error : missing ';' before '{'
……
Day10Doc.obj - 102 error(s), 0 warning(s)不知道是什么问题,有哪为高手能够给个提示?:)先谢谢了!

解决方案 »

  1.   

    在day10doc.h里添加class CLine;
      

  2.   

    The compiler expected a specific token (a language element other than white space) and found another token instead. Possible causes When using Managed Extensions for C++, a using directive had syntax error: 
    // C2143a.cpp
    // compile with: /LD /clr
    #using <mscorlib.dll>
    using namespace System.Reflection;   // C2143
    // try the following line instead
    // using namespace System::Reflection;
    The first non-whitespace character following an if statement should be a left parenthesis. The compiler cannot translate anything else: 
    // C2143b.cpp
    int main() {
       int j = 0;
       if (j < 25)   // C2143, missing semicolon
    }Missing closing brace, parenthesis, or semicolon on the line where the error is detected or a few lines above: 
    // C2143c.cpp
    class X
    {
       int member
    } x;          // C2143, missing ; on previous lineInvalid tag in a class declaration: 
    // C2143d.cpp
    class X
    {
       int member;
    } x;
    class + {};   // C2143, + is an invalid tag nameA label not attached to a statement. If you must place a label by itself (for example, at the end of a compound statement), attach it to a null statement: 
    // C2143e.cpp
    void func1()
    {
       end:      // C2143
    }            // this line is not a statement
    void func2()
    {
       end:      // OK
        ;        // this label attached to null statement
    }Invalid attribute syntax. Although the following instruction is valid in a MIDL file: 
    typedef [public] long MEMBERID;
    it is not valid in a C++ source code file. Instead, you would need to issue: [public] typedef long MEMBERID;
      

  3.   

    在day10doc.h里添加class CLine;