Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

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) {};
};
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.