I have a base class with a constructor that requires one parameter (string). Then I have a derived class which also has its’ own constructor. I want to instantiate the derived class and be able to set the parameter of the base class’s constructor as well.
class BaseClass {
public:
BaseClass (string a);
};
class DerivedClass : public BaseClass {
public:
DerivedClass (string b);
};
int main() {
DerivedClass abc ("Hello");
}
I’m not sure how to set the base class constructor’s parameter when calling the derived class.
You have two possibilities – inline:
or out of line:
more examples:
on initializer lists: