GCC compiler is being difficult
Hey, I'm kinda not really new to linux, but I am new to arch linux and earlier I was trying to run a simple program in c++. I proceeded to compile it with gcc like I always do
Code:
g++ main.cpp Code:
main.cpp:4:1: error: expected unqualified-id before ‘using’ Code:
#include "CartesianCoordinate.h" |
Quote:
Post all of main.cpp if it is small. Post the first several lines if it is big. I can't explain that error message without seeing the source code that produced it. But I'm pretty sure it represents an error in your source code. Where did the source code come from? Maybe it uses some Microsoft specific extension to C++ that is not supported by g++ Most of the above assumes you quoted the first error message. If you skipped over some earlier error messages, the one you quoted might mean nothing at all. |
What code are you trying to compile? By showing us, that would help out WAY more...............
|
How big is CartesianCoordinate.h ? Can you post the whole thing?
It now looks like the error might be in that file. C++ is complicated enough that an incorrect construct might look like an incomplete larger construct, so the compiler can't report the error until it is working on some later line unrelated to the actual error. #include files are processed at a level below the main compilation, so an error such as I just hypothesized often flows over from the end of an included file into the next source line in the file that included it. It may even flow across the intervening include of <iostream> |
Quote:
CartesianCoordinate.h [CODE] #include <iostream> using namespace std; class CartesianCoordinate { private: int x, y; public: void setX(int a); void setY(int b); int getX(); int getY(); CartesianCoordinate(int d, int e); } [\CODE] CartesianCoordinate.cpp [CODE] #include "CartesianCoordinate.h" using namespace CartesianCoordinate; CRectangle(int d, int e) { x = d; y = e; } void setX(int a) { x = a; } void setY(int b) { y = b; } int getX() { return x; } int getY() { return y; } [\CODE] |
Your error was lack of a ; at the end of the class definition.
Code:
#include <iostream> |
lol didn't notice that at all. thanks
|
Quote:
1) The code where the error was reported wasn't wrong, so an experienced programmer knows to look for an error in the preceding code. 2) The error in the preceding code needed to be the kind that couldn't be reported immediately and could flow out of the include file to the main file. Missing the ; at the end of the class definition is the most common such error, so the first thing I looked for, so I didn't need to look at any more. |
All times are GMT -5. The time now is 03:20 AM. |