Errors C2146, C2065, and C2143 occur when you compile code that includes consecutive closing chevrons (>>) at the end of the declaration in Visual C++ (155420)



The information in this article applies to:

  • Microsoft Visual C++, 32-bit Editions 4.0
  • Microsoft Visual C++, 32-bit Editions 4.1
  • Microsoft Visual C++, 32-bit Enterprise Edition 4.2
  • 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 4.2
  • 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 Q155420

SYMPTOMS

The compiler generates error C2146 followed by C2065 and finally C2143, all pointing to the same line in the source.

This sequence of errors can be caused by the following type of construct:
ClassA<int, ClassB<int>> iA ;
				
The problem is caused by the consecutive closing chevrons ">>" at the end of the declaration.

RESOLUTION

The solution is to put a space between the consecutive >>, so the above code becomes:
ClassA<int, ClassB<int> > iA ;
				
This is not a compiler bug. The language specification requires the space between the two ">"; otherwise, the lexical parser generates the token ">>", which is the largest possible token.

Sample Code

//Compile options needed: none
// test.cpp

template <class T>
class ClassB {} ;

template <class T1, class T2>
class ClassA{} ;

void main()
{
    ClassA<int, ClassB<int>> iA; // causes C2146, C2065, C2143
    //ClassA<int, ClassB<int> > iA;  //workaround

}
				

Modification Type:MajorLast Reviewed:6/3/2005
Keywords:kbtshoot kberrmsg kbCompiler kbCPPonly kbprb KB155420 kbAudDeveloper