0
Const member in class
Hi everyone. I have two constructors in my class : - first has no parameters; -second is initialising const variable; And that lead to have an error likeâ my class provides no initialiser for const memberâ. So I canât create non const object and I donât have an access to non const methods. Thank you
2 Answers
+ 2
Uninitialized constant member variables are not allowed. Therefore you need to make sure that you initialize your const member in every constructor that you write, even if it is just a default value like 0.
Otherwise there is a possibility that the first constructor with no parameters is called and the const member ends up not initialized.
Here is a rather similar problem:
https://stackoverflow.com/questions/4343934/uninitialized-constant-members-in-classes
0
Thanks for explainings .