&引用;没有与“调用”匹配的函数;在C+;中使用继承对象时出错+; 我是一个C++新手。我在另一个类中继承了一个类,但我收到一条错误消息,上面说:
&引用;没有与“调用”匹配的函数;在C+;中使用继承对象时出错+; 我是一个C++新手。我在另一个类中继承了一个类,但我收到一条错误消息,上面说:,c++,oop,inheritance,C++,Oop,Inheritance,错误:调用“Extended_queue::append(const Plane&)”时没有匹配的函数。 我做错了什么?我的部分代码如下: #include<iostream> using namespace std; #include "runway.h" Runway::Runway(int limit) /* Post: The Runway data members are initialized to record no prior Runway use and t
错误:调用“Extended_queue::append(const Plane&)”时没有匹配的函数。
我做错了什么?我的部分代码如下:
#include<iostream>
using namespace std;
#include "runway.h"
Runway::Runway(int limit)
/*
Post: The Runway data members are initialized to record no
prior Runway use and to record the limit on queue sizes.
*/
{
queue_limit = limit;
num_land_requests = num_takeoff_requests = 0;
num_landings = num_takeoffs = 0;
num_land_refused = num_takeoff_refused = 0;
num_land_accepted = num_takeoff_accepted = 0;
land_wait = takeoff_wait = idle_time = 0;
}
Error_code Runway::can_land(const Plane ¤t)
/*
Post: If possible, the Plane current is added to the
landing Queue; otherwise, an Error_code of overflow is
returned. The Runway statistics are updated.
Uses: class Extended_queue.
*/
{
Error_code result;
if (landing.size() < queue_limit)
result = landing.append(current);
else
result = fail;
num_land_requests++;
if (result != success)
num_land_refused++;
else
num_land_accepted++;
return result;
}
跑道.h的代码如下所示
#include "plane.h"
#include "queue.h"
enum Runway_activity {idle, land, takeoff};
class Runway {
public:
Runway(int limit);
Error_code can_land(const Plane ¤t);
Error_code can_depart(const Plane ¤t);
Runway_activity activity(int time, Plane &moving);
void shut_down(int time) const;
private:
Extended_queue landing;
Extended_queue takeoff;
int queue_limit;
int num_land_requests; // number of planes asking to land
int num_takeoff_requests; // number of planes asking to take off
int num_landings; // number of planes that have landed
int num_takeoffs; // number of planes that have taken off
int num_land_accepted; // number of planes queued to land
int num_takeoff_accepted; // number of planes queued to take off
int num_land_refused; // number of landing planes refused
int num_takeoff_refused; // number of departing planes refused
int land_wait; // total time of planes waiting to land
int takeoff_wait; // total time of planes waiting to take off
int idle_time; // total time runway is idle
};
跑道.h参考平面.h,包括以下内容:
enum Plane_status {
null, arriving, departing
};
class Plane {
public:
Plane();
Plane(int flt, int time, Plane_status status);
void refuse() const;
void land(int time) const;
void fly(int time) const;
int started() const;
private:
int flt_num;
int clock_start;
Plane_status state;
};
为什么编译器不能识别扩展队列从队列继承的方法 您的错误是将平面对象传递给 扩展队列::追加(常量队列条目和项目) 其中,Extended_queue是父类queue的子类
无论哪种方式,您都为函数提供了错误类型的参数。这就像将一个int传递给一个调用平面的函数。
append()
接受一个Queue\u条目
,而你试图将它传递给一个平面
。那么什么是平面
?@juanchopanza:我已经更新了这个问题,以包括平面。你是否尝试声明扩展队列登陆代码>在公共范围内?但如第一条注释中所述,append
不采用平面。
enum Plane_status {
null, arriving, departing
};
class Plane {
public:
Plane();
Plane(int flt, int time, Plane_status status);
void refuse() const;
void land(int time) const;
void fly(int time) const;
int started() const;
private:
int flt_num;
int clock_start;
Plane_status state;
};