This documentation is archived and is not being maintained.

Compiler Error C2146

syntax error : missing 'token' before identifier 'identifier'

The compiler expected token and found identifier instead.

Probable cause

  • A typographical error. Error C2065 usually precedes this error.

The following sample generates C2146:

// C2146.cpp
int main()
   intt x; // C2146 : missing semicolon before 'x'

You will also see this error as a result of compiler conformance work that was done for Visual Studio .NET 2003: explicit specializations no longer find template parameters from primary template.

The use of T from the primary template is not allowed in the explicit specialization. For code to be valid in the Visual Studio .NET 2003 and Visual Studio .NET versions of Visual C++, replace all instances of the template parameter in the specialization with the explicitly specialized type.

See Summary of Compile-Time Breaking Changes for more information.

The following sample compiles in Visual Studio .NET but will fail in Visual Studio .NET 2003:

// C2146b.cpp
// compile with: /LD
template <class T> 
struct S;

template <> 
struct S<int> 
   T m_t;   // C2146
   // Try the following line instead:
   // int m_t;