Share via


Compiler Error C2758

'const' : must be initialized in constructor base/member initializer list

The constructor does not initialize the const variable in an initializer list. The compiler leaves the constant undefined. Reference and const member variables must be given a value when initialized or in the constructor.

The following sample generates C2758:

// C2758.cpp
struct A {
   const int i;

   A(int i) {};   // C2758
   // try the following line instead
   // A(int i) : i(0) {};
};