类名是:CLine
我想在MyMDIDoc类里面用到这个CLine类,于是我在MyMDIDoc的头文件里面加入这个类:
于是我在这里面添加了:
// MyMDIDoc.cpp : implementation of the CMyMDIDoc class
//#include "stdafx.h"
#include "MyMDI.h"#include "MyMDIDoc.h"
#include "CntrItem.h"
#include "SrvrItem.h"
#include "Line.h"          //这个是我添加要用到的类#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
编译的时候就出现6个错误了!:
f:\myvc\mymdi\mymdidoc.h(41) : error C2143: syntax error : missing ';' before '*'
f:\myvc\mymdi\mymdidoc.h(41) : error C2501: 'CLine' : missing storage-class or type specifiers
f:\myvc\mymdi\mymdidoc.h(41) : error C2501: 'AddLine' : missing storage-class or type specifiers
F:\MyVC\MyMDI\MyMDIDoc.cpp(148) : error C2143: syntax error : missing ';' before '*'
F:\MyVC\MyMDI\MyMDIDoc.cpp(148) : error C2501: 'CLine' : missing storage-class or type specifiers
F:\MyVC\MyMDI\MyMDIDoc.cpp(149) : error C2501: 'AddLine' : missing storage-class or type specifiers

解决方案 »

  1.   

    #include "Line.h"   
    你的Line.h文件有问题 查查笔误 时候少;号等等
      

  2.   

    我这个类是在工作区窗口的ClassView选项卡中,选择树形视图中顶层对象(MyMDI类),按鼠标右键选择New Class项按提示建立的。
      

  3.   

    没有!因为我做完Line这个类的时候编译过,没有任何错误!就当我在MyMDIDoc里面加入CLine* AddLine (CPoint ptFrom,CPoint ptTo);的时候就出现错误了!
      

  4.   

    各位大大帮帮我啊!我在MyMDIDoc.ccp里面加也不行啊!还是有错误!
      

  5.   

    我不是很懂,我认为如下:
    CLine* AddLine (CPoint ptFrom,CPoint ptTo);
    这句有问题啊。
    *号表示指针,那么ADDLINE只是一个指针,还没空间呢。
      

  6.   

    代码发给我,我给你看看!
    [email protected]
      

  7.   

    出现那样的错误说明你的头文件引用不是正确的,不能说明你的类定义里是否有错误,建议这样把类加入,把类的.h和.cpp文件拷入你要加入的工程文件夹里,再在project     add to project       add files  加入两个类文件,再引用就可以了
      

  8.   

    我的那个类是在工程里自己添加的,代码也是自己写进去的,这个类就2个Cpoint类型数据,1个CLine和Draw两个函数,代码不超过10行!
      

  9.   

    在MyMDIDoc.h中加入 #include "Line.h"          //这个是我添加要用到的类
    或者加入class CDrawGraph;而你的程序是在MyMDIDoc.cpp中加入的。我模拟了一下应该可以。
      

  10.   

    楼主你这好像是在学习一本教程书上的例子吧
    你再仔细一点应是没有什么问题的
    你说得是不是<<Visual C++6.0高级开发教程>>这本书

    我也做过这本书
    没有什么错误呀
      

  11.   

    // MyMDIDoc.h : interface of the CMyMDIDoc class
    //
    /////////////////////////////////////////////////////////////////////////////#if !defined(AFX_MYMDIDOC_H__7FE79C6F_808F_4DCE_991E_01848DF65810__INCLUDED_)
    #define AFX_MYMDIDOC_H__7FE79C6F_808F_4DCE_991E_01848DF65810__INCLUDED_#include "line.h" // Added by ClassView
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    class CMyMDISrvrItem;class CMyMDIDoc : public COleServerDoc
    上面那些是我复制下来的东西!按你的意思是说在这里的哪个地方添加这句话啊?我曾经添加在这里的,它还是提示14个错误!:
    F:\MYVC\MyMDI\MyMDIDoc.cpp(152) : error C2065: 'CLine' : undeclared identifier
    F:\MYVC\MyMDI\MyMDIDoc.cpp(152) : error C2065: 'pLine' : undeclared identifier
    F:\MYVC\MyMDI\MyMDIDoc.cpp(152) : error C2660: 'Cline::Cline' : function does not take 2 parameters
    F:\MYVC\MyMDI\MyMDIDoc.cpp(156) : error C2065: 'm_oalines' : undeclared identifier
    F:\MYVC\MyMDI\MyMDIDoc.cpp(156) : error C2228: left of '.Add' must have class/struct/union type
    F:\MYVC\MyMDI\MyMDIDoc.cpp(161) : error C2317: 'try' block starting on line '154' has no catch handlers
    F:\MYVC\MyMDI\MyMDIDoc.cpp(161) : error C2065: 'Catch' : undeclared identifier
    F:\MYVC\MyMDI\MyMDIDoc.cpp(161) : error C2065: 'CMemory' : undeclared identifier
    F:\MYVC\MyMDI\MyMDIDoc.cpp(161) : error C2146: syntax error : missing ')' before identifier 'Exception'
    F:\MYVC\MyMDI\MyMDIDoc.cpp(161) : error C2059: syntax error : ')'
    F:\MYVC\MyMDI\MyMDIDoc.cpp(162) : error C2143: syntax error : missing ';' before '{'
    F:\MYVC\MyMDI\MyMDIDoc.cpp(169) : error C2541: delete : cannot delete objects that are not pointers
    F:\MYVC\MyMDI\MyMDIDoc.cpp(172) : error C2065: 'perr' : undeclared identifier
    F:\MYVC\MyMDI\MyMDIDoc.cpp(172) : error C2227: left of '->Delete' must point to class/struct/union谢谢各位!
      

  12.   

    我看的是人民邮电出版社的:《Visual C++使用培训教程》
      

  13.   

    代码我看了,Cline 这个类有问题。
    Cline : 要大写 CLine 
    因为你的构造函数   void CLine (CPoint ptFrom,CPoint ptTo);用的是大写。
    反正你要同一,要大写就全部大写。
    Cline *pLine=new CLine(ptFrom,ptTo);
    CLine 也写成一样的。class Cline : public CObject  
    {
    public:
    void Draw (CDC *pDC);
    void CLine (CPoint ptFrom,CPoint ptTo);
    Cline();          //构造函数
    virtual ~Cline(); //虚函数private:
    CPoint m_ptFrom;  //起点
    CPoint m_ptTo;    //目标点
    };
      

  14.   

    void CLine (CPoint ptFrom,CPoint ptTo); 前面的 void 去掉。
    m_oalines 不知从那里来得。
    你要好好看看 c++ 补一下基础的东西了!
      

  15.   

    谢谢你!你修改后能通过编译吗?我现在在做Excel的宏!做完了我再认真看看!唉!VC怎么不象VB那样会自动识别大小写的啊?在VB里设置了一个变量,在声明的时候是什么样的,用到那变量的时候自己就自动识别大小写,以适应声明时候的样子..........我是照抄书的,书本是一位教授的讲课来的!好像!谢谢!
      

  16.   

    则本垃圾书好差啊!它说变量名为m_ptPrevP,在程序中根本没出现过,就出现过m_ptPrevPos
    试问一个刚入门的怎么能看出来...........