Compiler Error C3366
TOC
Collapse the table of content
Expand the table of content
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. ArchiveDisclaimer

Compiler Error C3366

Error Message

'variable' : static data members of managed types must be defined within the class definition

You attempted to reference a static member of a .NET class or interface outside the definition of that class or interface.

The compiler needs to know the full definition of the class (to emit the meta-data after one pass) and requires static data members to be initialized within the class.

For example, the following example generates C3366:

// C3366.cpp
// compile with: /clr /c
ref class X {
   public:
   static int i;   // initialize i here to avoid C3366
};

int X::i = 5;      // C3366

The following example generates C3366:

// C3366_b.cpp
// compile with: /clr:oldSyntax /c
__gc struct X {
   static int i;   // initialize i here to avoid C3366
};

int X::i = 5;      // C3366
Show:
© 2016 Microsoft