0

I found this C++ constructor that uses an initialization list I don't understand what this convention is. I do know this initialization list can be use to instantiate a member of a instance with a param, but I've never seen a class constructor called from a list.

// G inherits from H
class GBackend : public HBackend {...}

// Constructor for G
// What is this HBackend constructor doing?
GBackend::GBackend(const BackendOptions& options) : HBackend(options), g_options(options) {...}

knowads
  • 705
  • 2
  • 7
  • 24
  • You mean you understand the initialization of the member `g_options`, but not the initialization of the base class `HBackend`? – JaMiT Mar 13 '22 at 23:10
  • It's like calling the `super` constructor in Java; it delegates to the parent class' constructor to initialize the fields declared there. – Silvio Mayolo Mar 13 '22 at 23:11
  • @JaMiT Yes. I've seen other C++ code that uses initialization lists to set a field within the instance, but I've never seen another constructor called. – knowads Mar 13 '22 at 23:11
  • @knowads Cool. That's an important detail when choosing which question to redirect this to. (It looks like the canonical question for "What is this weird colon-member syntax" covers only member initialization.) – JaMiT Mar 13 '22 at 23:20

0 Answers0