FIX: C2061, C2062, C2226, C2039 Occur When Using Enum Types (113118)
The information in this article applies to:
- Microsoft C/C++ for MS-DOS 7.0
- Microsoft Visual C++ 1.0
- Microsoft Visual C++ 1.5
- Microsoft Visual C++ 2.0
- Microsoft Visual C++ 4.0
- Microsoft Visual C++ 4.1
- Microsoft Visual C++ 4.2
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Learning Edition 5.0
This article was previously published under Q113118 SYMPTOMS
The compilers listed above may misinterpret a combination of an enumerated
type, a default parameter, and a constructor or function notation cast as a
syntax error and may incorrectly generate one of the following:
error C2226: syntax error : unexpected type '<type>'
-or-
error C2062: syntax error : unexpected type '<type>'
-or-
error C2039: '<class>' : is not a member of '<class2>'
-or-
error C2061: syntax error : identifier 'identifier'
CAUSE
The C++ compiler incorrectly parses declarations in which an enumerated
type is used as a parameter to either a constructor or a function notation
cast in a default parameter list. If there are other syntax errors in the
declaration line in question, then it is possible that an erroneous error
other than the ones listed might occur. The sample code shown below gives
examples of how to generate these errors.
This problem occurs only if an explicit construction [for example,
A(A::FALSE)] or function notation cast [that is, int(FALSE)] is called with
an enumerated type as an argument. If the compiler is allowed to do an
implicit conversion, the error will not occur:
void Func(int i = FALSE) { printf("%d\n",i); };
B(A a = A::FALSE);
RESOLUTION
In most cases (such as the examples below), the construction or function
notation cast is not explicitly needed, in which case it can be removed. If
this is not the case, the type cast (as opposed to function notation cast)
syntax for the function should be used instead. For example, the above
functions would be modified to:
void Func(int i = (int) FALSE) { printf("%d\n",i); };
B(A a = (A) A::FALSE);
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
This problem was corrected in Microsoft Visual C++ .NET.
Modification Type: | Minor | Last Reviewed: | 7/5/2005 |
---|
Keywords: | kbBug kbfix kbNoUpdate KB113118 |
---|
|