No Matching Function Call to Base class

前端 未结 4 1891
庸人自扰
庸人自扰 2020-12-06 14:41

Here I am trying to make a subclass of the base class, Airplane. In my main code I haven\'t tried to use either constructor yet as I am just trying to make sure I can make t

4条回答
  •  一生所求
    2020-12-06 15:03

    When this constructor is called

    Fighter::Fighter(int engines, int seats, string desc)
    {
        fNumEngines = engines;
        fNumSeats = seats;
        rangeSpeed = desc;
    }
    

    then it calls the default base class constructor. However class Airplane does not have the default constructor. It has a constructor with parameters

    Airplane(int, int);
    

    So you need explicitly calll the constructor in the mem-initializer list of the constructor Fighter

    For example

    Fighter::Fighter(int engines, int seats, string desc) : Airplane( engines, seats )
    {
        fNumEngines = engines;
        fNumSeats = seats;
        rangeSpeed = desc;
    }
    

    Also it is not clear why the data members of the base class and the derived class are duplicated.

提交回复
热议问题