Declaration of a constant member of a class has changed from Managed Extensions for C++ to Visual C++ 2005.
Although static const integral members are still supported, their linkage attribute has changed. Their former linkage attribute is now carried in a literal integral member. For example, consider the following Managed Extensions class:
В | Copy Code |
---|---|
public __gc class Constants { public: static const int LOG_DEBUG = 4; }; |
This generates the following underlying CIL attributes for the field (note the literal attribute):
В | Copy Code |
---|---|
.field public static literal int32 modopt([Microsoft.VisualC]Microsoft.VisualC.IsConstModifier) STANDARD_CLIENT_PRX = int32(0x00000004) |
While this still compiles under the new syntax:
В | Copy Code |
---|---|
public ref class Constants { public: static const int LOG_DEBUGВ = 4; }; |
it no longer emits the literal attribute, and therefore is not viewed as a constant by the CLR runtime:
В | Copy Code |
---|---|
.field public static int32 modopt([Microsoft.VisualC]Microsoft.VisualC.IsConstModifier) STANDARD_CLIENT_PRX = int32(0x00000004) |
In order to have the same inter-language literal attribute, the declaration should be changed to the newly supported literal data member, as follows,
В | Copy Code |
---|---|
public ref class Constants { public: literal int LOG_DEBUGВ = 4; }; |