Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual C++
C/C++ Build Errors
 Compiler Error C2143
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

Updated: November 2007

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
Plz help me in this home work      Farrosty ... Noelle Mallory - MSFT   |   Edit   |  
#include<iostream.h>
#include<string.h>
void PrintAll()

struct stud
{
char *name,*address,*date;
float Avg;
int *grade,Nog;
long ID;
stud *next,*prev;
};


void Add(stud**root)
{
int n,*T;
long ID;
char *name,*date,*address;
float Avg;

cout<<"Please Enter Student Name : ";
cin>> *name;
cout<<"Please Enter Student ID.No : ";
cin>> ID;
cout<<"Please Enter Student BirthDate : ";
cin>> *date;
cout<<"Please Enter Student Address : ";
cin>> *address;
cout<<"Please Enter The Number OF Grades : ";
cin>>n;
T=new int[n];
int sum=0;
for(int i=0;i<n;i++)
{
cin>>T[i];
sum+=T[i];
}

Avg=float(sum/n);

stud*p=NULL;
p=new stud;

strcpy(p->name,name);
strcpy(p->address,address);
strcpy(p->date,date);
p->grade=new int[n];
p->Nog=n;
p->grade=T;
p->ID=ID;
p->next=p->prev=NULL;
p->Avg;

if(*root==NULL)
{
*root=p;
(*root)->next=(*root)->prev=*root;
}
else {
stud*cur=*root;
stud*prev=cur->prev;

if (stricmp(cur->name,p->name)>0)
{
p->next=cur;
p->prev=cur->prev;
prev->next=p;
*root=p;
}//add at head

else if (stricmp(prev->name,p->name)<0)
{
prev->next=p;
p->next=prev->next;
p->prev=prev;
(*root)->prev=p;
}//add at tail

else
{
while(cur->next!=*root && stricmp(cur->name,p->name)<0)
{
prev=cur;
cur=cur->next;
}
p->next=cur;
cur->next=p;
p->prev=prev;
prev->next=p;
}
}
}// end of add


void Delete(stud**root)
{
if(*root==NULL) cout<<"There's no elements to be Deleted";
else
PrintAll(*root);
cout<<"please Enter The ID.No That You Want To Delete :";
long n;
{
cin>>n;
stud*cur=*root;
stud*prev=cur->prev;

if(cur->ID==n)
{
prev->next=cur->next;
cur->next->prev=prev;
*root=cur->next;
delete cur;
}//delete at head
else if(prev->ID==n)
{
cur->prev=prev->prev;
cur->prev->next=*root;
delete prev;
}//delete at tail

else
{
while(cur->ID!=n && cur->next!=*root)
{
prev=cur;
cur=cur->next;
}
if(cur->next==*root)
cout<<"Not Found";

else
{
prev->next=cur->next;
cur->next->prev=prev;
delete cur;
}
}//delete at middle
}
}//end Of delete

void SearchID(stud*root)
{
int n;
if(root==NULL) cout<<"List Is Empty ";
else
long n;
{
cin>>n;
stud*cur=root;
stud*prev=cur->prev;

if(cur->ID==n) cout<<"Not FounD";
else
if(prev->ID==n) cout<<"FounD";
else
{
while(cur->next!=root && cur->ID!=n)
cur=cur->next;
if(cur->next==root)
cout<<"NoT FounD";
else
cout<<"FounD";
}
}
}// end of SearchID

void SearchName(stud*root)
{
if(root==NULL) cout<<"Empty List , Please Fill It Up";
else
char *m;
{
cin>>*m;
stud*cur=root;
stud*prev=cur->prev;

if(stricmp (cur->name,m)==0) cout<<"FounD" ;
else
if(stricmp (prev->name,m)==0) cout<<"FounD" ;
else
{
while(cur->next!=root && stricmp(cur->name,m)!=0)
cur=cur->next;
if(cur->next=root) cout<<"NoT FounD";
else
cout<<"FounD";
}
}
}

void ComputeAvg(stud*root)
{
stud*p=r;
float sum=0;
int n=0;
p=p->next;

while(p)
{
sum+=p->Avg;
n++;
}
cout<<"The All Average= "<<sum/n;
}

void Display()
{
cout<<"Please Choose Your Operation" <<endl;
cout<<"1.Add Student"<<endl;
cout<<"2.Delete Student"<<endl;
cout<<"3.Search By Name Or By ID.No"<<endl;
cout<<"4.Compute All Students Average"<<endl;
cout<<"5.EnD Program"<<endl;

}

void PrintNode(struct p)
{
cout<<p.name<<endl;
cout<<p.date<<endl;
cout<<p.ID<<endl;
cout<<p.address<<endl;
int *s=p.grade;
while(s)
{
cout<<*s;
s++;
}
cout<<p.avg;
}

void PrintAll(stud*r)
{
if(p==NULL) cout<<"Empty";
else
{
stud*p=r;
while (p->next!=root)
{
PrintNode(*p);
p=p->next;
}
PrintNode(*p);
}
}

void main ()
{
stud *r=NULL;

while (1)
{
Display();
int op;
cin>>op;

if (op==1) Add(&root);

else if (op==2) Delete(&root);

else if (op==3)
{
int op2;
cout<<"1.Search By Name . ";
cout<<"2.Search By ID.No " ;
cin<<op2;

if (op2==1) SearchName(root);

else if (op2==2) SearchID(root);

else
cout<<"Invalid Entry";
}

else if (op==4) ComputeAvg(root);

else if (op==5) break;

else cout<<"Invalid Entry ";
}
}








** but i have 2 errors and i cant solve them
1. error C2143: syntax error : missing ';' before '<class-head>'
2. fatal error C1004: unexpected end of file found Error executing cl.exe.



[Noelle Mallory - MSFT] Please post questions to the MSDN Forums at http://forums.microsoft.com/msdn. You will likely get a quicker response through the forum than through the Community Content.
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker