我在VC中自己定义了一个类,在这个类中需要使用本工程的视图类作为成员变量,我在头文件中都加入了Include视图类头文件的语句,但编译总是通不过,提示说我Include的文件过多,请问如何解决这个问题?谢了

解决方案 »

  1.   

    #pragma once
    Specifies that the file will be included (opened) only once by the compiler in a build. This can reduce build times as the compiler will not open and read the file after the first #include of the module.For example,// header.h
    #pragma once
      

  2.   

    你是不是你再.cpp和.h都包含了一次啊?
      

  3.   

    #include "CxxxDoc.h"
    #include "CxxxView.h"
      

  4.   

    我试了一下,确实有问题
    我定义了class CTest  
    然后在里面定义成员变量CSDIView view1;
    #include "SDIView.h"
    还是有一个错误,
    “error C2248: 'CSDIView::CSDIView' : cannot access protected member declared in class 'CSDIView'”
      

  5.   

    你把要你需要的.cpp .h加入你的工程没有?
    用菜单上面那个Add files to Project
      

  6.   

    没有问题呀!
    STEP1:
    在当前的工程目录中加入自己的定义的类!
    为了简单起见,在类中使用的是视图类的指针变量,这样省去了修改视图的构造函数的麻烦!
    //The project name is :TestWin.dsp//The file:test.h
    class CTest
    {
    private:
      CTestWinView *m_pView;
    public:
      CTest();
      void SetView(CTestWinView *pView);
      CTestWinView* GetView();
    };//The file:test.cpp
    #include "stdafx.h"//must include this file!
    #include "TestWinDoc.h"
    #include "TestWinView.h"
    #include "Test.h"CTest::CTest()
    {
     m_pView=NULL;
    }
    CTestWinView* CTest::GetView()
    {
      return m_pView;
    }
    void CTest::SetView(CTestWinView *pView)
    {
      m_pView=pView;
    }STEP2:
    使用菜单Project->Add to project->files将文件test.h和test.cpp添加到工程中即可!
      

  7.   

    我试了一下,还是不行,错误信息提示停在在CMyView* m_pParent这句话上,sytax error:missing ";" before "*",可我肯定没有少写分号
      

  8.   

    怪事!你在自己定义的类的实现文件中是否进行了类似下面的头文件包含(具有顺序性)
    #include "stdafx.h"//must include this file!
    #include "TestWinDoc.h"
    #include "TestWinView.h"
    #include "Test.h"------------------------
    必须在
    #inlude "test.h"之前,依次包含:
    #include "stdafx.h"//must include this file!
    #include "TestWinDoc.h"//used in the CTestWinView.h
    #include "TestWinView.h"//used in the CTest