You are currently offline, waiting for your internet to reconnect

You receive a compiler C2061 error message in different versions of Visual C++

This 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.
This behavior is by design.

Visual C++ 6.0

In 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 2002

However, 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 2003

In 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.

Article ID: 815646 - Last Review: 05/12/2007 06:38:21 - Revision: 1.2

  • Microsoft Visual C++ .NET 2003 Standard Edition
  • Microsoft Visual C++ .NET 2002 Standard Edition
  • Microsoft Visual C++ 6.0 Service Pack 5
  • kbprod2web kbprb kbtemplate kbcompiler KB815646