In an inherited class constructor, I want to use a class constant member that hides the base class one from the base class constructor:
#include <string>
#include <iostream>
class BaseClass {
private:
const int constant_variable { 21 };
public:
int mutable_variable;
BaseClass(): mutable_variable(constant_variable) {};
};
class DerivedClass: public BaseClass {
private:
const int constant_variable { 42 };
public:
using BaseClass::BaseClass;
};
int main () {
DerivedClass dc;
std::cout << dc.mutable_variable << std::endl; // 21, but I want it to be 42
return 0;
}
In the example code, for instance, BaseClass' constructor uses its own value of constant_variable while I'd like it to use the DerivedClass' constant_variable.
How to do this in c++?
constintegers in everyDerivedClassobject.