Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error C2143: syntax error : missing ';' before 'using' [closed]

Tags:

c++

static

this is my header:

#ifndef HEADER_H
#define HEADER_H

class Math
{
    private:
        static enum names {amin = 27 , ali = 46};

    public:
        static void displayMessage();

}


#endif // HEADER_H

and this is the header definition:

#include <iostream>
#include <iomanip>
#include "Header.h"

using namespace std;

void Math::displayMessage()
{
    cout<<amin<<setw(5)<<ali<<endl;
}

and this is the main:

#include <iostream>
#include "Header.h"

using namespace std;

enum Math::names;

int main()
{
    Math::displayMessage();
}

i got these errors:

error C2143: syntax error : missing ';' before 'using'  
error C2143: syntax error : missing ';' before 'using'  

one of them is for main and the other is for header definition, i have encountered several time in my programming, could explain that for me in this situation,

please help me

best regards

Amin khormaei

like image 401
Amin Khormaei Avatar asked Feb 27 '14 07:02

Amin Khormaei


3 Answers

After preprocessing, your source code[1] for your "header definition" becomes like

// iostream contents

// iomanip contents


class Math
{
    private:
        static enum names {amin = 27 , ali = 46};

    public:
        static void displayMessage();

}

using namespace std;

void Math::displayMessage()
{
    cout<<amin<<setw(5)<<ali<<endl;
}

Let's now see error C2143: syntax error : missing ';' before 'using'. Where is using in the above code? What is it before using?

}
^ This    

using namespace std;

Because of the part of the error that says missing ';', we must add that missing ;.

};
 ^

[1]More precisely called a "translation unit".

like image 128
Mark Garcia Avatar answered Nov 19 '22 12:11

Mark Garcia


You're missing a ; after the definition of class Math.

like image 7
Mike Seymour Avatar answered Nov 19 '22 11:11

Mike Seymour


missing ';' before 'using'

Just read what it tells you. There is a missing ; before using. Then look at your code, where did you use using? (the compiler likely told you the line)

#include "Header.h"

using namespace std;

What's before using? The header include.

The compiler most likely goes through your code in a linear manner, so what it did when it saw #include "Header.h" was to go through that file. Meaning that the error will be the very end of "Header.h". And indeed, there is a missing ; at the end of the class declaration, just like the compiler told you.

like image 1
Lundin Avatar answered Nov 19 '22 10:11

Lundin