LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 03-24-2011, 03:28 PM   #1
coolbeans777
LQ Newbie
 
Registered: Mar 2011
Distribution: Gentoo with KDE, Kubuntu 11.10
Posts: 16

Rep: Reputation: 2
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
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
 
Old 03-24-2011, 03:32 PM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by coolbeans777 View Post
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.

Last edited by johnsfine; 03-24-2011 at 03:37 PM.
 
Old 03-24-2011, 03:33 PM   #3
corp769
LQ Guru
 
Registered: Apr 2005
Location: /dev/null
Posts: 5,818

Rep: Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007Reputation: 1007
What code are you trying to compile? By showing us, that would help out WAY more...............
 
1 members found this post helpful.
Old 03-24-2011, 03:40 PM   #4
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
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>

Last edited by johnsfine; 03-24-2011 at 03:44 PM.
 
Old 03-24-2011, 03:44 PM   #5
coolbeans777
LQ Newbie
 
Registered: Mar 2011
Distribution: Gentoo with KDE, Kubuntu 11.10
Posts: 16

Original Poster
Rep: Reputation: 2
Quote:
Originally Posted by johnsfine View Post
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]
 
Old 03-24-2011, 03:45 PM   #6
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
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);
};

Last edited by johnsfine; 03-24-2011 at 03:47 PM.
 
Old 03-24-2011, 03:48 PM   #7
coolbeans777
LQ Newbie
 
Registered: Mar 2011
Distribution: Gentoo with KDE, Kubuntu 11.10
Posts: 16

Original Poster
Rep: Reputation: 2
lol didn't notice that at all. thanks
 
Old 03-24-2011, 03:53 PM   #8
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by coolbeans777 View Post
lol didn't notice that at all.
That comes with experience:

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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Compiler Benchmarks Of GCC, LLVM-GCC, DragonEgg, Clang LXer Syndicated Linux News 0 11-08-2010 05:11 PM
no gcc, no cc no c compiler pyrether DamnSmallLinux 5 09-09-2006 01:14 AM
Is updateing gcc difficult? BajaNick Programming 3 04-11-2006 01:26 PM
GCC Compiler..... mani_iips Linux - Newbie 4 08-08-2005 08:55 PM
GCC compiler aviceda Linux - Newbie 5 08-13-2004 06:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration