Error no appropriate default constructor available

前端 未结 2 1637
暖寄归人
暖寄归人 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.
      {
      }
      
    0 讨论(0)
  • 2021-01-29 02:09

    Ticket doesn't have a default constructor, therefore List can't be default-constructed since it inherits from Ticket, and List does not call a base constructor in Ticket.

    0 讨论(0)
提交回复
热议问题