在這裏,我試圖做一個基類飛機的子類。在我的主代碼中,我還沒有嘗試使用任何一個構造函數,因爲我只是想確保我可以讓子類Fighter正常工作。沒有匹配函數調用基類
它給我確切的錯誤是
no matching function for call to 'Airplane:Airplane()'
,並表示它涉及到在Fighter.cpp
Fighter::Fighter(int engi, int seat, string description)
Fighter.cpp
#include "Fighter.h"
Fighter::Fighter(int engin, int seat, string description)
{
fNumEngines = engi;
fNumSeats = seat;
rangeAndSpeedDesc = description;
}
這行代碼
Fighter.h
#include "Airplane.h"
using namespace std;
#ifndef FIGHTER_H_
#define FIGHTER_H_
class Fighter:public Airplane {
private:
int fNumSeats;
int fNumEngines;
string rangeAndSpeedDesc;
}
Airplane.cpp
#include "Airplane.h"
using namespace std;
Airplane::Airplane(int engines, int seats)
{
numSeats = seats;
numEngines = engines;
}
我讓他們擺脫困惑,我明白爲什麼他們現在不需要!感謝您的幫助和額外的提示! – 4Percent