We recommend using Visual Studio 2017

Compiler Error C2899


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Visual Studio 2017 Documentation. typename cannot be used outside a template declaration

The typename keyword can be used only in a template definition or declaration. In a template declaration, it can be used in two ways:

// C2899.cpp  
// compile with: /c  
template<typename T>   
class X {};  
// Another way  
template<class T>   
struct XX {  
   typename T::A a;   // T::A is a type  

The following sample generates C2899:

// C2899b.cpp  
// compile with: /c  
struct Y {  
   typedef int B;  
   typename Y::B b;   // C2899