Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
however, it kept showing this rather obnoxious error
Code:
main.cpp:4:1: error: expected unqualified-id before ‘using’
what packages should I install through pacman to get this to work properly?
Code:
#include "CartesianCoordinate.h"
#include <iostream>
using namespace std;
int main() {
CartesianCoordinate point(5, 6);
int q = point.getX();
int c = point.getY();
cout << "Point at 'point': (" << q << " ," << c << ")" << endl;
return 0;
}
Last edited by coolbeans777; 03-24-2011 at 03:35 PM.
Reason: Forgot to put in code of main.cpp
what packages should I install through pacman to get this to work properly?
I'm pretty sure this won't be fixed by installing a package.
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.
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>
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.
Yea, sorry
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>
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);
};
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.