Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Compiler Warning (level 2) C4356

Error Message

'member' : static data member cannot be initialized via derived class

The initialization of a static data member was ill formed. The compiler accepted the initialization.

This is a breaking change in the Visual C++ .NET 2003 compiler. See Summary of Compile-Time Breaking Changes for more information.

For code that works the same in all versions of Visual C++, initialize the member through the base class.

Use the warning pragma to suppress this warning.

The following sample generates C4356:

// C4356.cpp
// compile with: /W2 /EHsc
#include <iostream>

template <class T>
class C {
   static int n;

class D : C<int> {};

int D::n = 0; // C4356
// try the following line instead
// int C<int>::n = 0;

class A {
   static int n;

class B : public A {};

int B::n = 10;   // C4356
// try the following line instead
// int A::n = 99;

int main() {
   using namespace std;
   cout << B::n << endl;

Community Additions

© 2015 Microsoft