You receive a compiler C2061 error message in different versions of Visual C++ (815646)
The information in this article applies to:
- Microsoft Visual C++ .NET (2003)
- Microsoft Visual C++ .NET (2002)
- Microsoft Visual C++, 32-bit Editions 6.0
SYMPTOMSThis article describes the C2061 compiler error message that
is received in different versions of Microsoft Visual C++. In
Microsoft Visual C++ 6.0 and in Microsoft Visual C++ .NET, you receive the
following error message: Compiler Error C2061 syntax error
: identifier 'identifier' In Visual C++ .NET 2002, you may also
receive the following error message: error C2947:
expecting '>' to terminate template-parameter-list,found '>' In
Visual C++ .NET 2003, you may also receive the following error message: warning C4346: 'T::type' : dependent name is not a type prefix
with 'typename' to indicate a type. STATUS This
behavior is by design.MORE INFORMATIONVisual C++ 6.0In Visual C++ 6.0, a C2061 compiler error occurs when you enclose
an initializer in parentheses. To resolve this behavior, enclose the declarator
in parentheses or define the declarator as typedef. This code specifies two fixes:
class X {};
class Y {};
class Z {};
class W : public X, public Y, public Z {};
void func ( W* pW )
{
// This will cause a Compiler Error C2061 in Visual C++ 6.0.
X* pX ( pW ); // Error: unexpected identifier 'pW'
// To fix the Compiler Error C2061 in Visual C++ 6.0,
// Either enclose the declarator in parentheses:
Y ( *pY ) ( pW ); // The declarator is now in parentheses.
// Or define the declarator as typedef:
typedef Z *pZ_t;
pZ_t pZ ( pW ); // The Z declarator is defined as typedef.
}
Visual C++ .NET 2002However, the code in the "Visual C++ 6.0" section does not cause
an error in Visual C++ .NET 2002. In Visual C++ .NET 2002, the following code
causes the C2061 error when it is compiled with the /Za compiler switch. You may also receive a C2947 error with the
C2061 error. template <class T, T::type (*pFunc)() > Visual C++ .NET 2003In Visual C++ .NET 2003, the C2061 error occurs when the compiler
detects an expression as a class template argument. You receive the C2061 error
even when the /Za compiler switch is not used. In addition to the C2061 error, you
may also receive a C2947 error and a C4346 error. You may modify the
code in Visual C++ .NET 2003 by using the typename keyword as follows: template <class T, typename T::type (*pFunc)() >
void MyFunction();
When you use template parameter as a type, you must use the typename keyword. According to ANSI C++ standards, a qualified name that
refers to a type type specifier
and that depends on a template parameter must be prefixed by the typename keyword. REFERENCESFor more information about the ANSI C++ Standard for
templates, visit the following Web site:
Modification Type: | Minor | Last Reviewed: | 1/12/2006 |
---|
Keywords: | kbProd2Web kbprb kbtemplate kbCompiler KB815646 kbAudDeveloper kbAudITPRO |
---|
|