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
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".
You're missing a ;
after the definition of class Math
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With