I avoid the problem by using the same name for the arguments as members that they initialize. Search rules indicate that a name refers to an argument when used in a member initializer.
Subtle errors are likely if the constructor is too complex; but not a problem if you simply initialize the participants in the initializer list.
Otherwise, GCC will give a warning about using an uninitialized value with reasonable warning settings, such as -Wall (or, possibly, -Wextra ), or, more specifically, -Wuninitialized . I think it could also be -Winit-self or similar if you want to be more specific.
source share