Compiler Error C2438
Visual Studio 2015
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at Compiler Error C2438.
identifier' : cannot initialize static class data via constructor
A constructor is used to initialize a static member of a class. Static members must be initialized in a definition outside the class declaration.
The following sample generates C2438:
// C2438.cpp
struct X {
X(int i) : j(i) {} // C2438
static int j;
};
int X::j;
int main() {
X::j = 1;
}
Show: