Code:
struct A{
const bool const_some_write_once_flag;
A(): const_some_write_once_flag(false) { }
};
struct B: public A{
B(): const_some_write_once_flag(true) { }
};
the error is: class ‘B’ does not have any field named ‘const_some_write_once_flag’. I believe that it’s because while being in the constructor of B, the object being created is not yet of type A, because the “inherited slice” of A has not yet been initialized.
I’ve tried several workarounds with no luck, and I’ll omit them here. Is there a way to achieve what I’m trying to do?
In its initializer list,
Bcan only initialize its own data members, its direct base classes, and any virtual base classes.const_some_write_once_flagis none of these; it is a data member ofA. It can only be initialized by a constructor ofA.