Error C2258 and error C2252 occur if you try to perform in-place initialization of static const integral member data in Visual C++ (241569)
The information in this article applies to:
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
This article was previously published under Q241569 SYMPTOMS You may get the following error message if you try to
perform in-place initialization of static const integral member data.
error C2258: illegal pure syntax, must be '= 0'
error C2252: 'x' : pure specifier can only be specified for functions
Please refer to the sample in the "More Information" section for
details. CAUSE The compiler does not support in-place initialization of
static const integral member data as specified in the C++ standard (section
9.2) quoted in the following:
4 - A member-declarator can contain a constant-initializer only if it declares a static member of integral or enumeration
type. WORKAROUND Use one of the following workarounds:
- Use enum instead of static const int:
enum{x = 3};
- Instantiate the member outside the class:
const int A::x=3;
STATUSMicrosoft has confirmed that this is a bug in the Microsoft
products that are listed at the beginning of this article.
Modification Type: | Major | Last Reviewed: | 6/2/2005 |
---|
Keywords: | kbprb kbtshoot kberrmsg kbCompiler kbCPPonly kbpending KB241569 kbAudDeveloper |
---|
|