description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | ||
---|---|---|---|---|---|---|---|
Learn more about: Compiler Error C2758 |
Compiler Error C2758 |
11/04/2016 |
|
|
1d273034-194c-4926-9869-142d1b219cbe |
'member': a member of reference type must be initialized
Compiler error C2758 is caused when the constructor does not initialize a member of reference type in an initializer list. The compiler leaves the member undefined. Reference member variables must initialized when declared or be given a value in the initialization list of the constructor.
The following sample generates C2758:
// C2758.cpp
// Compile by using: cl /W3 /c C2758.cpp
struct A {
const int i;
A(int n) { }; // C2758
// try the following line instead
// A(int n) : i{n} {};
};