Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual C++
C/C++ Build Errors
 Compiler Error C2143

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Visual C++ Concepts: Building a C/C++ Program
Compiler Error C2143

Error Message

syntax error : missing 'token1' before 'token2'

The compiler expected a specific token (a language element other than white space) and found another token instead. C2143 can occur in different situations.

See Knowledge Base article Q241706 for information on this error when using a function-try block.

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

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

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

When attempting to compile a source code file 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 following 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 a few lines 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();
}

Attempting 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
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker