由于情况复杂,我也只能大概说一下我有Building和Controller两个类,然后我再Building的h里已经包含了Controller的h文件,然后在Building类里申明一个Controller型的成员变量,可是编译的时候编译器老是提醒我Controller未定义,请问一下这到底是怎么回事!!!

解决方案 »

  1.   

    注意笔误,大小写等
    文件是否insert到工程中
      

  2.   

    在 controller中添加Biulding 申明 class Biulding;
      

  3.   

    肯定没有笔误,检查过很多次了,而且肯定insert到工程中了
      

  4.   

    我用的不是全局变量,extern好像不行吧
      

  5.   

    #ifndef MYBUILDING_WIND
    #define MYBUILDING_WIND#include "Person.h"
    #include "Controller.h"
    #include <VECTOR>
    #include <STDLIB.H>
    #include <TIME.H>
    #include "PaintStruct.h"
    #include "ObjectType.h"
    #include "Floor.h"
    #include "PersonOfFloor.h"const float FloorHeight = 3.0f;
    const int   FloorAmount = 11;
    const int   LiftAmount = 3;using namespace std;class Building
    {
    friend class Controller;
    public: Building(int FloorAmount = 10); ~Building()
    {
    }
    void Initial(int FloorAmount = 10,int LiftAmount = 3)
    {
    if(m_nFloor != FloorAmount)
    {
    m_nFloor = FloorAmount;
    m_vecFloor.clear();
    for( int i = 0; i < m_nFloor; i++)
    {
    Floor newFloor(FloorHeight);
    m_vecFloor.push_back(newFloor);
    }
    //m_cController.Initial(FloorAmount,LiftAmount);
    }
    if(LiftAmount != m_cController.m_vecLift.size())
    {
    m_cController.Initial(FloorAmount,LiftAmount);
    }
    } int GetFloor() const
    {
    return m_nFloor;
    }

    void OneSecondPass();

    void AcceptOnePerson(Person* CurrentPerson)
    {
    delete CurrentPerson;
    CurrentPerson = 0;
    }
    void InitializeSeed() const
    {
    srand((unsigned int) time(0)); 
    } int RandIn(int Low, int High) const
    {
    if(Low > High)
    {
    int Temp = Low ;
    Low  = High;
    High = Temp;
    }
    int _IntervalSize = High - Low + 1;
    int _RandomOffset = rand() % _IntervalSize;
    return Low + _RandomOffset;
    }
    float GetTotalHeight(int FloorNumber) const;

    float GetFloorHeight(int FloorNumber) const;

    vector<PaintStruct*>& GetPaintInfo();protected:
    void RandomCreatePerson();
    int RandInt() const;
    void SetFloor(int nFloor)
    {
    if (nFloor > 0)
    {
    m_nFloor = nFloor;
    }
    }private:
    int  m_nFloor;
    Controller    m_cController;
    vector<Floor>    m_vecFloor;
    vector<PaintStruct*> m_paintInfo;
    OBJECTTYPE    m_enType;
    };#endif--------------------Configuration: Lift1 - Win32 Debug--------------------
    Compiling...
    Controller.cpp
    c:\documents and settings\wind.mywind\桌面\lift1\building.h(97) : error C2079: 'm_cController' uses undefined class 'Controller'
    Lift.cpp
    c:\documents and settings\wind.mywind\桌面\lift1\building.h(97) : error C2079: 'm_cController' uses undefined class 'Controller'
    Building.cpp
    main.cpp
    Error executing cl.exe.Lift1.exe - 2 error(s), 0 warning(s)
      

  6.   

    原来是坐电梯模拟的。把class Controller也贴一下。
      

  7.   

    #include "Building.h"
    #include "PersonOfFloor.h"
    #include "STATUS_ENUM.h"
    #include "Lift.h"
    #include <VECTOR>
    #include <DEQUE>
    #include "Distance.h"
    #include "UserInput.h"const int MAXDISTANCE = 10001;
    const bool StopLiftStartMoving = true;using namespace std;class Controller  
    {
    private:
    friend class Building;
    friend class Lift;
    public:
    Controller(Building* Father = 0,int FloorOfBuilding = 1,int LiftinController = 3);
    ~Controller()
    {
    }
    void Initial(int FloorAmount = 10,int LiftAmount = 3);
    void AcceptOnePerson(Person*, bool IsArrived);
    void RefreshLiftCommand();
    void OneSecondPass();
    void GetPaintInfo(vector<PaintStruct*>& PaintVec);
    private:
    bool DeliverToLift(Distance* CurrentDistance, int size, int FloorNumber, bool IsUp);
    Person* SendPersonToLift(int CurrentFloor, LIFTSTATUS CurrentStatus);
    void RebuildStopDeque();
    void EmptyLiftTable();
    bool DeliverUpDeque();
    bool DeliverDownDeque(); void Sort(Distance* First, int size);

    Building*              m_ptrFatherBuilding ;
    vector<FloorHashNode> m_vecPersonInBuilding ;
    deque<int>     m_dequeUpStop ;
    deque<int>     m_dequeDownStop         ;
    vector<Lift>     m_vecLift ;
    UserInput             m_userInput ;
    };