Error no appropriate default constructor available

前端 未结 2 1647
暖寄归人
暖寄归人 2021-01-29 01:16

I am implementing a list class with node and iterator, that creates a list of type Ticket, which is an object that i have defined in a class, but when i try to compile it says t

2条回答
  •  一个人的身影
    2021-01-29 01:55

    When you don't include code to initialize a base class in the initialization list of a constructor of a derived class, the base class is initialized using the default constructor. In other words,

    List::List()
    {
    }
    

    is equivalent to:

    List::List() : Ticket()
    {
    }
    

    Since Ticket does not have a default constructor, the compiler does not have any way to initialize Ticket from the posted code.

    You can resolve this problem by one of the following methods:

    1. Add a default constructor to Ticket
    2. Update List::List() to use the only constructor of Ticket in the initialization list.

      List::List() : Ticket(0, 0, 0) // You need to figure out what values
                                     // make sense in your application.
      {
      }
      

提交回复
热议问题