146. Inheritance

Question.5

A derived class needs to pass arguments to the base constructor:

class GPIO {
   int pin;
public:
   GPIO(int p) : pin(p) {}
};

class LED : public GPIO {
   bool state;
public:
   LED(int p) : GPIO(p), state(false) {}
};

Why is GPIO(p) in the initializer list?

Need Help? Refer to the Quick Guide below

Select Answer

Restart quiz!