编译出错,急寻帮助 由于情况复杂,我也只能大概说一下我有Building和Controller两个类,然后我再Building的h里已经包含了Controller的h文件,然后在Building类里申明一个Controller型的成员变量,可是编译的时候编译器老是提醒我Controller未定义,请问一下这到底是怎么回事!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 注意笔误,大小写等文件是否insert到工程中 在 controller中添加Biulding 申明 class Biulding; 肯定没有笔误,检查过很多次了,而且肯定insert到工程中了 我用的不是全局变量,extern好像不行吧 #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.cppc:\documents and settings\wind.mywind\桌面\lift1\building.h(97) : error C2079: 'm_cController' uses undefined class 'Controller'Lift.cppc:\documents and settings\wind.mywind\桌面\lift1\building.h(97) : error C2079: 'm_cController' uses undefined class 'Controller'Building.cppmain.cppError executing cl.exe.Lift1.exe - 2 error(s), 0 warning(s) 原来是坐电梯模拟的。把class Controller也贴一下。 #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 ;}; 如何将CString对象转换为字符数组 半透明不规则界面完美解决方案 关于组合框的问题 关于MFC的问题 一道人工智能的小问题 JPG文件处理问题?急 各位工具栏上的图形都是自己描的吗? VC+数据库问题(高手进) 请教大家 一个问题栈遭到破坏的问题 DLL多次动态加载的问题。做过的进来看~! windows自带的线程池 大家看看这个strstr的难度用法稳定否
文件是否insert到工程中
#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)
#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 ;
};