Say I have a base class with a flag inside of it which derived classes have to set:
struct Base
{
bool flag;
Base(bool flag):flag(flag) {}
};
I want to configure which derived classes set the flag to true
/false
in a data-driven way - i.e. I'd like to configure this from a header.
struct Derived1 : Base
{
Derived1() : Base( expr ) {}
};
Where expr
is something (don't know what yet) that is able to get the info from the header - tell whether Derived1
should make flag
true or false. Ideally, I'd get an error if I make a new derived class but fail to specify the flag in the header, but this isn't mandatory. This way I can just modify a single central location to make changes.
What's the idiomatic approach for this?