Compiler Error C2143

syntax error : missing 'token1' before 'token2'

The compiler expected a specific token (that is, a language element other than white space) and found another token instead.

For information about this error when it occurs when you are using a function-try block, see Knowledge Base article 241706.

Check the C++ Language Reference to determine where code is syntactically incorrect. Because the compiler may report this error after it encounters the line that causes the problem, check several lines of code that precede the error.

C2143 can occur in different situations.

When /clr is used and a using directive has a syntax error:

// C2143a.cpp
// compile with: /clr /c
using namespace System.Reflection;   // C2143
using namespace System::Reflection;

When you are trying to compile a source code file by using using CLR syntax without using /clr:

// C2143b.cpp
ref struct A {   // C2143 error compile with /clr
   void Test() {}
};

int main() {
   A a;
   a.Test();
}

The first non-whitespace character that follows an if statement should be a left parenthesis. The compiler cannot translate anything else:

// C2143c.cpp
int main() {
   int j = 0;

   // OK
   if (j < 25)
      ;

   if (j < 25)   // C2143
}

Missing closing brace, parenthesis, or semicolon on the line where the error is detected or on one of the lines just above:

// C2143d.cpp
// compile with: /c
class X {
   int member1;
   int member2   // C2143
} x;

Invalid tag in a class declaration:

// C2143e.cpp
class X {
   int member;
} x;

class + {};   // C2143 + is an invalid tag name
class ValidName {};   // OK

A label not attached to a statement. If you must place a label by itself, for example, at the end of a compound statement, attach it to a null statement:

// C2143f.cpp
// compile with: /c
void func1() {
   // OK
   end1:
      ;

   end2:   // C2143
}

An unqualified call is made to a type in the Standard C++ Library:

// C2143g.cpp
// compile with: /EHsc /c
#include <vector>
static vector<char> bad;   // C2143
static std::vector<char> good;   // OK

Missing typename keyword:

// C2143h.cpp
template <typename T>
struct X {
   struct Y {
      int i;
   };
   Y memFunc();
};
template <typename T>
X<T>::Y X<T>::memFunc() {   // C2143
// try the following line instead
// typename X<T>::Y X<T>::memFunc() {
   return Y();
}

If you try to define an explicit instantiation:

// C2143i.cpp
// compile with: /EHsc /c
// template definition
template <class T>
void PrintType(T i, T j) {}

template void PrintType(float i, float j){}   // C2143
template void PrintType(float i, float j);   // OK

In a C program, variables must be declared at the beginning of the function, and they cannot be declared after the function executes non-declaration instructions.

// C2143j.c

int main()

{

int i = 0;

i++;

int j = 0; // C2143

}