I have a in-class initialized const member in a derived class which I'd like to pass to the constructor of the base class.
Example:
class Base{
public:
Base(int a) : i(a){}
private:
int i;
};
class Derived : Base{
public:
Derived() : Base(a){}
private:
const int a = 7;
};
int main(){
Derived d;
}
However this spawns an uninitialized error:
field 'a' is uninitialized when used here [-Wuninitialized]
I was under the impression that const initializing it would set the value directly allowing it to be passed from the derived ctor in this manner. Am I doing something wrong or am I under the wrong impression? When are the const in-class initialized members initialized?