Compiler Error C3845
'member': only static data members can be initialized inside a ref class or value type
A data member inside a managed type cannot be initialized unless it is static.
The following sample generates C3845:
// C3845.cpp
// compile with: /clr
using namespace System;
ref class A {
public:
const Int32 n = 7; // C3845
};
Possible resolution:
// C3845b.cpp
// compile with: /clr /c
using namespace System;
ref class A {
public:
static Int32 n = 7;
};
Managed Extensions for C++
The following sample generates C3845:
// C3845c.cpp
// compile with: /clr:oldSyntax
#using <mscorlib.dll>
using namespace System;
__gc class A {
public:
const Int32 m = 7; // C3845
};
Possible resolution:
// C3845d.cpp
// compile with: /clr:oldSyntax /c
#using <mscorlib.dll>
using namespace System;
__gc class A {
public:
static Int32 n = 7;
};