No Matching Function Call to Base class

前端 未结 4 1900
庸人自扰
庸人自扰 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:13

    The error contains the information that you need. You havent defined a default constructor for class Airplane. When you construct the child class Fighter in this function:

    Fighter(int, int, string);
    

    There will be a call to construct the base class. In your implementation you do not explicitly call the base class constructor:

    Airplane::Airplane(int engines, int seats)

    And you have no default constructor, so what should the compiler do? It complains.

    You wiether need to define a default constructor:

    Airplane::Airplane()
    

    Or call an existing constructor in the constructor for fighter:

    Fighter::Fighter(int engines, int seats, string desc) : Airplane(engines, seats)
    

提交回复
热议问题