1

I have a base class ShowTicket with parameterized constructor:

    //constructor
        ShowTicket(const char* Row, const char* SeatNumber):
        sold_status{false},
        row(Row),
        seat_number(SeatNumber)
        {}

I am creating a derived class, SportTicket that will take the same parameters as ShowTicket but will add a new boolean value to keep track of beer_sold. The problem is I do not know how to tell C++ that I still want sold_status to be intialized to false in the SportTicket Constructor.

I tried doing this:

    //Constructor
    SportTicket(const char* Row, const char* SeatNumber):
    ShowTicket(Row, SeatNumber),
    beer_sold{false},
    sold_status{false}
    {}

But I received the following error message:

Member initializer 'sold_status' does not name a non-static data member or base class

Is sold_satus already initialized to false because the variable is inherited from the base classes initialization list or is there a different syntax I can use to bring this variable into my derived class?

1
  • 1
    sold_status belongs to the base class so, yes, it's initialized to false if that's the only constructor in ShowTicket. Commented May 23, 2022 at 19:09

1 Answer 1

3

The constructor of the class ShowTicket itself initializes its data member sold_status to false

//constructor
    ShowTicket(const char* Row, const char* SeatNumber):
    sold_status{false},
    row(Row),
    seat_number(SeatNumber)
    {}

So in the derived class just remove the line

sold_status{false}

because it is incorrect and redundant.

//Constructor
SportTicket(const char* Row, const char* SeatNumber):
ShowTicket(Row, SeatNumber),
beer_sold{false}
{}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.