Hi everyone, I'm just a beginner so don't judge me. I have searched on Google before I came here but it didn't help me really.
Here is the problem: I have an abstract class called Flight and two classes which are derived from Flight. Their names are RegularFlight and CharterFlight. How do I call the constructor from Flight class in my derived classes, so my derived classes can inherit the protected members of Flight class?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
class Flight
{
protected:
char* startDestination;
char* finalDestination;
char* takeoffDate;
char* takeoffTime;
int numberOfReservedSeats;
public:
Flight();
~Flight();
Flight(char* sDest, char* fDest, char* takeoffD, char* takeoffT,
int reservations);
};
#include"Flight.h"
class RegularFlight : public Let
{
private:
int numberOfSeatsOnThePlane;
public:
void reserveOneSeat;
RegularFlight();
RegularFlight(int numOfSeatsOnThePlane);
~RegularFlight();
};
#include"Flight.h"
class CharterFlight : public Let
{
private:
int numberOfSeatsInRegularPlane;
int numberOfSeatsInIrregularPlane;
public:
CharterFlight();
CharterFlight(int regular, int irregular);
~CharterFlight();
};
|
I didn't write all the functions I use in this program since I guess it's not needed right now. I only have to say that class Flight contains pure virtual functions which are later predefined in derived classes.
The constructor Flight(char* sDest, char& fDest, char*takeoffD, char* takeoffT,
int reservations) is used to initiate protected members of my abstract class Flight and I'd like to call it with the constructors RegularFlight(int numOfSeatsOnThePlane) and CharterFlight(int regular, int irregular).
I'd like to inherit the protected members of my base class to my derived classes since I need to make a program that has as little as possible code duplication. That means that both classes use the same members, and the only members that are different are defined in each subclass as private.
I hope that I didn't confuse you very much because I have a lot of this going in my mind. :D Every help is appreciated.