本文介绍了我如何正确地从基类继承?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,名为飞机。我想将它设置为一个名为 fixedWing 子类。然后我希望 fixedWing 类有3个子类;第一个叫做 Glider ,第二个叫做 Jet ,第三个叫做 Propellers



我收到以下错误:



fixedwing.h(11):错误C2504:'飞机':基类未定义

fixedwing.h(35):警告C4584:'螺旋桨':基类'FixedWing'已经是'Jet'的基类

fixedwing.h(10):注意:看'FixedWing'的声明

fixedwing.h(26):注意:看看'Jet'的声明



我尝试过:



Aircraft.h

I have a class called Aircraft. I would like to set it to have a subclass called fixedWing. I would then like the fixedWing class to have 3 subclasses; The first called Glider, the second called Jet and the third called Propellers.

I am getting the following errors:

fixedwing.h(11): error C2504: 'Aircraft': base class undefined
fixedwing.h(35): warning C4584: 'Propeller': base-class 'FixedWing' is already a base-class of 'Jet'
fixedwing.h(10): note: see declaration of 'FixedWing'
fixedwing.h(26): note: see declaration of 'Jet'

What I have tried:

Aircraft.h

#pragma once

#include "stdafx.h"
#include "FixedWing.h"
#include <string>
#include <iostream>
#include <fstream>
using namespace std;

class Aircraft;

class Aircraft{
	int regNo;
	string manufacturer;
	string serialNo;
	string productionDate;
	string owner;
	string annualInspection;
	int minSpeed;
	int maxSpeed;
	int maxClimbRate;
public:
	Aircraft(); // default construct
	Aircraft(int);
};





FixedWing.h



FixedWing.h

#pragma once

#include "stdafx.h"
#include "Aircraft.h"
#include <string>

using namespace std;

// Fixed Wing class derived from Aircraft
class FixedWing : public Aircraft
{
public:
	FixedWing();
	//FixedWing(int regNo);
};

// (sub#1) Gliders to fixed wing
class Glider : public FixedWing
{
public:
	Glider();
private:
};

// (sub#2) Jets to fixed wing
class Jet : public FixedWing
{
public:
private:
	int hoursInOperation;
};

// (sub#3) Propellers to fixed wing
class Propeller : Jet,FixedWing
{
public:
private:
	int hoursInOperation;
};





我觉得解决方案正在盯着我,但我似乎无法找到它。任何人都可以帮助我吗?



非常感谢提前!



I feel that the solution is staring me in the face but I just can't seem to find it. Could anyone be able to assist me?

Many thanks in advance!

推荐答案



这篇关于我如何正确地从基类继承?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-29 05:57