错误:字段' flyairplane'有不完整的类型 错误:字段' flypilot'有不完整的类型 。 。
#include <iostream>
#include <sstream>
using namespace std;
/* Prototypes */
class date;
class Time;
class passenger;
class pilot;
class fly;
class Airplane;
class Destination;
class lane;
class Time;
class era;
class priorityQueue;
/* class defines */
class fly{
public:
void setflyserialNumber(string serial){
flySerialNumber = serial;
}
void setAirPlane(Airplane a){
flyairplane = a;
}
void setPilot(pilot p){
flyPilot = p;
}
void setflyEra(era E){
airplaneEra = E;
}
void setflyDestination(Destination D){
airplaneDestination = D;
}
void setflyTime(Time t){
flyTime = t;
}
void setflyDate(date D){
flyDate = D;
}
void setPassengerNumber(int a){
passengerNumber = a ;
}
void setNumberOfWaiters(int n){
numberOfWaiters = n ;
}
string getFlySerialNumber(){
return flySerialNumber;
}
string getPriority(){
stringstream stm; // crisis$fuel$flyDuration$sitnumbers$
stm << flyairplane.getCrisisState()<< "$"<< flyairplane.getExistFuel()<< "$" << flyDuaration << "$" << flyairplane.sitNumber <<"$" ;
return stm.str();
}
private:
string flySerialNumber;
Airplane flyairplane;
pilot flyPilot;
/* fly contributes */
era airplaneEra;
Destination airplaneDestination;
date flyDate;
Time flyTime;
int passengerNumber;
int numberOfWaiters;
int flyDuaration;
};
class passenger {
public :
passenger(){};
passenger(string n ,string fn , long int nc,date * bt ){
name = n ;
familyName = fn;
nationCode = nc ;
birthDate = bt;
}
void setName(string nm , string fn){
name = nm ;
familyName = fn ;
}
string getName(){
stringstream stm;
stm << name << " " << familyName ;
return stm.str();
}
void SetNationalCode(long int Nc) {
nationCode = Nc ;
}
long int getNationalCode(){
return nationCode;
}
private:
string name;
string familyName;
long int nationCode;
date *birthDate;
};
class pilot{
private :
string name;
string family;
int personallyCode;
date *birthDate;
date *empDate;
string Degree;
int flyTimeDuration;
public :
pilot(){};
pilot(string n , string famil , int persoalCode , date *birthD , date *empd , string deg ,int flyTimeDur){
name = n;
family = famil;
personallyCode = persoalCode;
birthDate = birthD ;
empDate = empd ;
Degree = deg;
flyTimeDuration = flyTimeDur ;
}
};
class era{
public:
string eraname;
// location in coordinate system can define here
date flyDate;
Time flyTime;
};
class Destination{
public:
string destinationName;
// location in coordinate system can define here
date flyDate;
Time flyTime;
};
class date{
public:
int day;
int month;
int year;
date(){};
~date(){};
string dateToserial()
{
stringstream stm;
stm << year << month << day;
return stm.str();
}
int dateToNumber(){
int t = day + month + year ;
return t;
}
};
class Time{
public :
Time(int h , int mins , int sec){
hour = h;
minute = mins;
second = sec;
}
Time(){}
int hour;
int minute;
int second;
};
class Airplane{
//friend class fly;
public :
Airplane(){ }
Airplane(string name,date *genesis,int sitnum , int weight ,string moedl ,string produceFactor , int motors ,float fuelcapacity ){
AirplaneName = name;
genesisYear = *genesis;
}
// void addPassenger(Passenger pass);
string getState (){
stringstream tstm;
tstm << "fuelValue : "<< fuelCapacity << " passengerNumber:"<<passangerNumbers ;
return tstm.str();
}
string getAirplaneSerialnumber(){
stringstream tempstr;
tempstr << genesisYear.dateToserial() << weight << motorNumber << fuelCapacity;
return tempstr.str();
}
void setexistfuel(float f){
existFuel = f;
}
float getExistFuel(){
return existFuel;
}
void setCrisisState(bool b){
crisis = b;
}
bool getCrisisState(){
return crisis;
}
private:
bool crisis = false;
string AirplaneName;
string serialNumber;
date genesisYear;
int sitNumber;
int passangerNumbers;
int weight;
string modelType;
string producerFactory;
int motorNumber;
float fuelCapacity;
float existFuel;
};
class lane{
public:
lane();
lane(string lsn , int cap , bool state , bool pstate)
{
laneSerialNumber=lsn;
capacity = cap;
status = state;
portStatus = pstate;
usedCapacity=0;
//ctor
}
~lane()
{
//dtor
}
int capacity;
int usedCapacity;
bool status;
bool portStatus;
int discharingTime;
void setport(bool ps)
{
if(ps) portStatus=true; // takeOff
else
portStatus = false; // landing
}
void setStatus(bool state)
{
if(state) status = true;
else
status = false;
}
bool getStatus()
{
return status;
}
void setlaneSerialNumber(string lsn)
{
laneSerialNumber=lsn;
}
string getlaneSerialNumber()
{
return laneSerialNumber;
}
string toString()
{
stringstream stm;
stm << laneSerialNumber << "{ "<< "Capacity : "<< capacity<< " used :"<<usedCapacity<<" _ Status : "<<status << " _ Direcion : "<< portStatus << " _ DischaringTime" <<discharingTime << endl;
return stm.str();
}
string generatelaneSerialNumber()
{
stringstream stm;
stm << capacity << usedCapacity << status << portStatus << discharingTime;
laneSerialNumber = stm.str();
return stm.str();
}
protected:
private:
string laneSerialNumber="";
};
class manager{
// priority_queues for takeoff & landing
// return value of the takeoff queue at time to watchtower
// get the Objects for landing from watchtower then add it to queue by priority
// manage priority of queue in dangerous occasions return last priority to watchtower to landing
/* Objects contents */
// in every queue object there is a fly object that contain name & etc of air plane
// & there is a number that is combined from fuel value & Events type of landing , that created by watchtower
public :
};
/* Global functions */
int main()
{
lane lane1("lane1",3,true,true);
Airplane plane1;
cout << "\n";
cout << lane1.generatelaneSerialNumber() << endl;
cout << "\n";
cout << lane1.toString() << endl;
cout << plane1.getState();
return 0;
}
有人可以帮忙吗?谢谢!
答案 0 :(得分:0)
在C ++中,如果对象是成员变量,则不能使用前向声明。
以下是关于何时可以使用正向声明的帖子:When can I use a forward declaration?
一个简单的解决方法是在类Fly之前指定所有类,但是你应该做的是在自己的文件中创建所有类(头和cpp,用于声明和定义)和#include必要的头文件。
答案 1 :(得分:0)
因为试点类是向前宣布的。
Airplane flyairplane;
pilot flyPilot;
...
class pilot{
private :
string name;
string family;
int personallyCode;
date *birthDate;
date *empDate;
string Degree;
int flyTimeDuration;
public :
pilot(){};
pilot(string n , string famil , int persoalCode , date *birthD , date *empd , string deg ,int flyTimeDur){
name = n;
family = famil;
personallyCode = persoalCode;
birthDate = birthD ;
empDate = empd ;
Degree = deg;
flyTimeDuration = flyTimeDur ;
}
尝试不使用前向声明