2

Hi I'm doing a function to find a transport by number but I'm experiencing an error I don't know why.

I have to abstract base class "Transport".

class Transport
{
protected:
    int transportNumber;
    char transportName[20];
    char company[20];
    struct tm dateOfMaking;
    double speed;
    char propertyType[20];
    char transportType[20];

public:
    Transport();
    Transport(int,char*, char*, struct tm, double, char*, char*);
    ~Transport();

    virtual char* GetName() = 0;
    virtual bool Warning(double);
    virtual void Print() = 0;
    virtual void Save() = 0;
    virtual int GetPassengerNumber();
    virtual double GetEmptyWeight();
    char * GetTransportType() { return transportType; }
    int GetTransportNumber() { return transportNumber;}
};

This class inherits from Transport.

class Aerial : public Transport
{
protected:
    int engineNumber;
    double length;
public:
    Aerial() {}
    Aerial(int, char*, char*, struct tm, double, char*, char*, int, double);
    ~Aerial();
};

I have this class that inherits from class Aerial.

class PassengerPlane : public Aerial
{
private:
    int seatNumber;
    double Bagswieght;
public:
    PassengerPlane() {}
    PassengerPlane(int, char*, char*, struct tm, double, char*, char*, int, double, int,double);
    ~PassengerPlane();
    char* GetName();
    bool Warning(double);
    int GetPassengerNumber() { return seatNumber; }
    void Save();
    void Print();
};

With the ProgrammeManagement::TransporSearchByNumber(int TN) function returning the Transport* value You have stored and searched for objects in the file in this function as follows:

Transport* ProgrammeManagement::TransporSearchByNumber(int TN)
{
    char num;
    int x = 1;
    PassengerPlane e;
    Transport *T;
    fstream file(Type,ios::in);
    fstream fil(TransportFilePath,ios::in);
    while(file.get(num))
    {
        if( num == '1')
        {

            fil.read((char*)&e,sizeof(PassengerPlane));
            T = &e;
            if( TN == T->GetTransportNumber()){
            x = 0;
            return T;
            }
        }
    }

    if(x){
        cout << "Not found";
    }
    file.close();
    fil.close();
}

In my main I do the following:

Transport*s;
  s = ProgrammeManagement::TransporSearchByNumber(2);
  s->Print();

but when I call the Print() function on Transport, I get the following error (on runtime, it compiles):

pure virtual method called
terminate called without an active exception

Any help how to solve this issue.

Thank you very much in advance!

Amin abd
  • 21
  • 1
  • 2

0 Answers0