双星号语法&帮助调用成员函数
我正在做一个有航空课程的项目。 Airline 类包含动态 Flight 对象数组的变量。
在我的 Airlines 类中(无法编辑或更改,这是为我分配的头文件):
//Airline.h
class Airline {
public:
Airline(); // default constructor
Airline(int capacity); // construct with capacity n
void cancel(int flightNum);
void add(Flight* flight);
Flight* find(int flightNum);
Flight* find(string dest);
int getSize();
private:
Flight **array; // dynamic array of pointers to flights
int capacity; // maximum number of flights
int size; // actual number of flights
void resize();
};
//Flight.h
class Flight {
public:
Flight();
// Default constructor
Flight(int fnum, string destination);
void reserveWindow();
void reserveAisle();
void reserveSeat(int row, char seat);
void setFlightNum(int fnum);
void setDestination(string dest);
int getFlightNum();
string getDest();
protected:
int flightNumber;
bool available[20][4]; //only four seat types per row; only 20 rows
string destination;
};
我正在尝试实现类中的查找方法之一。
为此,我有:
Flight* Airline::find(int flightNum){
bool found = false;
for(int i = 0; i < size; i++){
if(array[i].getflightNum() == flightNum){
found = true;
return array[i];
}
}
if(!found)
return 0;
}
// Return pointer to flight with given number if present, otherwise
// return 0.
但它说我在尝试调用 getFlightNum() 方法时需要一个类类型。我真的不明白这个错误。我没有正确调用该方法吗?正确的语法是什么?
I'm working a program where there's an Airline class. The Airline class contains a vairable to an array of dynamic Flight objects.
In the Airlines class I have (which can't be edited or changed, this was the header file given to me for the assignment):
//Airline.h
class Airline {
public:
Airline(); // default constructor
Airline(int capacity); // construct with capacity n
void cancel(int flightNum);
void add(Flight* flight);
Flight* find(int flightNum);
Flight* find(string dest);
int getSize();
private:
Flight **array; // dynamic array of pointers to flights
int capacity; // maximum number of flights
int size; // actual number of flights
void resize();
};
//Flight.h
class Flight {
public:
Flight();
// Default constructor
Flight(int fnum, string destination);
void reserveWindow();
void reserveAisle();
void reserveSeat(int row, char seat);
void setFlightNum(int fnum);
void setDestination(string dest);
int getFlightNum();
string getDest();
protected:
int flightNumber;
bool available[20][4]; //only four seat types per row; only 20 rows
string destination;
};
I'm trying to impliment one of the find methods in the class.
for that, I have:
Flight* Airline::find(int flightNum){
bool found = false;
for(int i = 0; i < size; i++){
if(array[i].getflightNum() == flightNum){
found = true;
return array[i];
}
}
if(!found)
return 0;
}
// Return pointer to flight with given number if present, otherwise
// return 0.
But it's saying that I need a class type when trying to call the getFlightNum() method. I don't really understand the error. Am I not calling the method correctly? What is the correct syntax?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您正在处理指针而不是实际对象,请尝试以下操作:
Since you are dealing with pointers instead of actual objects, try this: