Export (0) Print
Expand All
Expand Minimize

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 ...
   // A(int i) : i(0) {


int main() {
© 2015 Microsoft