By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,498 Members | 1,564 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,498 IT Pros & Developers. It's quick & easy.

"expected unqualified-id before 'using'"

P: n/a
This is just bizarre. for the following snippet of code:
#include <string>
using std::string;
I get the error message:
expected unqualified-id before "using"
expected `,' or `;' before "using"
which doesn't make any sense to me - a preprocessor directive isn't
ended by a semicolon, and I must've used this little chunk of code
hundreds of times. This happened after I chopped up an unwieldy large
class into a couple of smaller classes, and this code ran just fine
before I made the changes.

The REALLY weird thing is that if I comment out the "using" statement,
the compiler jumps into the file "functexcept.h" included with Dev-C++,
and gives me the same basic error message with regards to the following
snippet:
#include <exception_defines.h>

namespace std
{ ...
This time it informs my that the "unqualified id" lies before "namespace".

WTF!! Can anybody help me out here? I have no idea what I might have
changed that could possibly have caused this. I have basic C++ skills
and am no comp sci wiz. I just write basic progs to help me study or
parse and modify text files.
Jul 23 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
"Squid Seven" <te*********@squidseven.com> wrote in message
news:mJ********************@adelphia.com...
This is just bizarre. for the following snippet of code:
#include <string>
using std::string;
I get the error message:
expected unqualified-id before "using"
expected `,' or `;' before "using"


Probably the header file string is corrupted, likely at the end...

Use your compiler's options to get the preprocessor output to see what the
compiler is actually seeing.

Ali

Jul 23 '05 #2

P: n/a

"Squid Seven" <te*********@squidseven.com> wrote in message
news:mJ********************@adelphia.com...
This is just bizarre. for the following snippet of code:
#include <string>
using std::string;
I get the error message:
expected unqualified-id before "using"
expected `,' or `;' before "using"
which doesn't make any sense to me - a preprocessor directive isn't ended
by a semicolon, and I must've used this little chunk of code hundreds of
times. This happened after I chopped up an unwieldy large class into a
couple of smaller classes, and this code ran just fine before I made the
changes.

The REALLY weird thing is that if I comment out the "using" statement, the
compiler jumps into the file "functexcept.h" included with Dev-C++, and
gives me the same basic error message with regards to the following
snippet:
#include <exception_defines.h>

namespace std
{ ...
This time it informs my that the "unqualified id" lies before "namespace".

WTF!! Can anybody help me out here? I have no idea what I might have
changed that could possibly have caused this. I have basic C++ skills and
am no comp sci wiz. I just write basic progs to help me study or parse
and modify text files.


A few ideas/possibilities. Guesses, really.

One is that you've got a header file or a line in that source file before
this with incorrect line endings. If you've transported a file between
Windows and Mac, for instance, your linde endings get screwed up, and cause
weird behavior like this. If it's a line you copied and pasted from
somewhere, try deleting some of the code and re-typing it in by hand.

Another idea is that a previous compile is somehow messing with you, perhaps
because you changed source files or paths. Try a complete, clean rebuild.

I've also seen problems on some compilers if the end of a header file is a
line-comment (using //), or is a class definition without a trailing
semicolon. Check the ends of your headers and see if they're ok.

Oh, and check your compiler/build settings and paths, to be sure you haven't
selected some target/library/framework you didn't intend.

-Howard
Jul 23 '05 #3

P: n/a


Howard wrote:
"Squid Seven" <te*********@squidseven.com> wrote in message
news:mJ********************@adelphia.com...
This is just bizarre. for the following snippet of code:
#include <string>
using std::string;
I get the error message:
expected unqualified-id before "using"
expected `,' or `;' before "using"
which doesn't make any sense to me - a preprocessor directive isn't ended
by a semicolon, and I must've used this little chunk of code hundreds of
times. This happened after I chopped up an unwieldy large class into a
couple of smaller classes, and this code ran just fine before I made the
changes.

The REALLY weird thing is that if I comment out the "using" statement, the
compiler jumps into the file "functexcept.h" included with Dev-C++, and
gives me the same basic error message with regards to the following
snippet:
#include <exception_defines.h>

namespace std
{ ...
This time it informs my that the "unqualified id" lies before "namespace".

WTF!! Can anybody help me out here? I have no idea what I might have
changed that could possibly have caused this. I have basic C++ skills and
am no comp sci wiz. I just write basic progs to help me study or parse
and modify text files.

A few ideas/possibilities. Guesses, really.

One is that you've got a header file or a line in that source file before
this with incorrect line endings. If you've transported a file between
Windows and Mac, for instance, your linde endings get screwed up, and cause
weird behavior like this. If it's a line you copied and pasted from
somewhere, try deleting some of the code and re-typing it in by hand.


Ali said that it might be a corrupted header file too. He suggest I use
my compiler settings to get my preprocessor output. I've spent the past
half-hour trying to figure out how to do that. How does a header file
get corrupted? I didn't transfer or move the files or in any way
interact with them except indirectly by modifying my OWN files in
Dev-C++. Urgh. I am SO FRUSTRATED!
Another idea is that a previous compile is somehow messing with you, perhaps
because you changed source files or paths. Try a complete, clean rebuild.

tried the complete rebuild, no luck
I've also seen problems on some compilers if the end of a header file is a
line-comment (using //), or is a class definition without a trailing
semicolon. Check the ends of your headers and see if they're ok.

Oh, and check your compiler/build settings and paths, to be sure you haven't
selected some target/library/framework you didn't intend.

-Howard

Jul 23 '05 #4

P: n/a

Ali said that it might be a corrupted header file too. He suggest I use
my compiler settings to get my preprocessor output. I've spent the past
half-hour trying to figure out how to do that. How does a header file get
corrupted? I didn't transfer or move the files or in any way interact
with them except indirectly by modifying my OWN files in Dev-C++. Urgh.
I am SO FRUSTRATED!


When all else has failed me before, I created a new project. Then, I added
in the files from the original project, one or two at a time, (commenting
out code that used files that I hadn't added back yet). Eventually, I
either found a file that, when included, screwed everything up again, or
else it miraculously worked when it was all put back together. A major pain
in the ass, but it's worked.

Perhaps more simple than this is to continue what you tried, commenting out
includes here and there until the weird error goes away. The last thing you
removed should at least give you a *hint* of where the problem might lie.

I also use the CodeWarrior IDE to load files in and make sure all the line
endings are correct. There are probably freeware tools that do that too,
though...I think CodeWarrior's expensive.

Sorry you're having so much trouble. I wish you luck in fixing it without
too much pain...

-Howard

Jul 23 '05 #5

P: n/a
On Thu, 14 Jul 2005 16:45:28 -0400, Squid Seven
<te*********@squidseven.com> did courageously avow:
This is just bizarre. for the following snippet of code:
#include <string>
using std::string;
If you are specifically identifying the namespace in front of the data
type try dropping the keyword using.

std::string

I believe 'using' is used this way.

using namespace std;

That would allow you to use everything in string without needing a the
namespace every time. And this is a good thing. If you're doing a
lot of I/O do you really want to be typing std::cout and std::cin for
every time you need it?


I get the error message:
expected unqualified-id before "using"
expected `,' or `;' before "using"
which doesn't make any sense to me - a preprocessor directive isn't
ended by a semicolon, and I must've used this little chunk of code
hundreds of times. This happened after I chopped up an unwieldy large
class into a couple of smaller classes, and this code ran just fine
before I made the changes.

The REALLY weird thing is that if I comment out the "using" statement,
the compiler jumps into the file "functexcept.h" included with Dev-C++,
and gives me the same basic error message with regards to the following
snippet:
#include <exception_defines.h>

namespace std
{ ...
This time it informs my that the "unqualified id" lies before "namespace".

WTF!! Can anybody help me out here? I have no idea what I might have
changed that could possibly have caused this. I have basic C++ skills
and am no comp sci wiz. I just write basic progs to help me study or
parse and modify text files.

Ken Wilson

Amer. Dlx. Tele, Gary Moore LP, LP DC Classic w/P90s,
Jeff Beck Strat, Morgan OM Acoustic,
Rick 360/12, Std. Strat (MIM), Mesa 100 Nomad,
Mesa F-30

"Goodnight Austin, Texas, wherever you are."
Jul 23 '05 #6

P: n/a
OK, tell me if my logic here is good. I completely uninstalled Dev-C++
and deleted the directory it was in. Then I reinstalled it, reinstalled
all my libraries, and then tried to compile the program again, with the
same problem. This means that corrupt standard library header files,
specifically <string>, *can't* be the cause of the problem, correct? So
the problem must be in my code?

I am going to try good old-fashioned troubleshooting on my own code now
(though I can't imagine how changes there caused this problem), but I'm
hoping that someone can confirm for me that the measures taken above do
in fact confirm that the problem *is* in my own code.

Thanks much for your help guys.

Rick N. Backer wrote:
On Thu, 14 Jul 2005 16:45:28 -0400, Squid Seven
<te*********@squidseven.com> did courageously avow:

This is just bizarre. for the following snippet of code:
#include <string>
using std::string;

If you are specifically identifying the namespace in front of the data
type try dropping the keyword using.

std::string

I believe 'using' is used this way.

using namespace std;

That would allow you to use everything in string without needing a the
namespace every time. And this is a good thing. If you're doing a
lot of I/O do you really want to be typing std::cout and std::cin for
every time you need it?


I get the error message:
expected unqualified-id before "using"
expected `,' or `;' before "using"
which doesn't make any sense to me - a preprocessor directive isn't
ended by a semicolon, and I must've used this little chunk of code
hundreds of times. This happened after I chopped up an unwieldy large
class into a couple of smaller classes, and this code ran just fine
before I made the changes.

The REALLY weird thing is that if I comment out the "using" statement,
the compiler jumps into the file "functexcept.h" included with Dev-C++,
and gives me the same basic error message with regards to the following
snippet:
#include <exception_defines.h>

namespace std
{ ...
This time it informs my that the "unqualified id" lies before "namespace".

WTF!! Can anybody help me out here? I have no idea what I might have
changed that could possibly have caused this. I have basic C++ skills
and am no comp sci wiz. I just write basic progs to help me study or
parse and modify text files.


Ken Wilson

Amer. Dlx. Tele, Gary Moore LP, LP DC Classic w/P90s,
Jeff Beck Strat, Morgan OM Acoustic,
Rick 360/12, Std. Strat (MIM), Mesa 100 Nomad,
Mesa F-30

"Goodnight Austin, Texas, wherever you are."

Jul 23 '05 #7

P: n/a
Ian
Squid Seven wrote:
This is just bizarre. for the following snippet of code:
#include <string>
using std::string;

Are there any headers included before string? They might be broken.

Try compiling the snippet on its own.

Ian
Jul 23 '05 #8

P: n/a
Squid Seven wrote:
OK, tell me if my logic here is good. I completely uninstalled Dev-C++
and deleted the directory it was in. Then I reinstalled it, reinstalled
all my libraries, and then tried to compile the program again, with the
same problem. This means that corrupt standard library header files,
specifically <string>, *can't* be the cause of the problem, correct? So
the problem must be in my code?

I am going to try good old-fashioned troubleshooting on my own code now
(though I can't imagine how changes there caused this problem), but I'm
hoping that someone can confirm for me that the measures taken above do
in fact confirm that the problem *is* in my own code.


That would indeed confirm it. I mispoke earlier when I said you
couldn't use 'using' as you did but, after some looking, you were right
in its useage.

These compilers are usually very robust. If it has never caused you a
problem why would it decide to suddenly and on code you've used before.
I almost always take the blame for compiler errors and rightfully so,
except when working with MS libraries.

You stated you busted up a bunch of code. All it takes is one
semicolon out of place and it can create anything from a single
compiler error, to a fistfull of them sometimes. This is a not
uncommon occurrence if you're cutting and pasting large amouts of text
a single character is easy to lose sight ot.

Jul 23 '05 #9

P: n/a
Found it - a missing semicolon after the brackets of a class definition.

AAaAAHHHH!!! arghhhhhhhhhhh... !@%$@$#&^#@$%&@ (noise of forehead
striking desk repeatedly)

I still don't understand how it led to that strange little error in a
very distant area of the app, but I'm just glad that I can resume
getting things done... after four hours of banging my head against my
desk, reinstalling my development suite and libraries from scratch, and
scouring the web for irrelevant posts.

Sigh.

Thanks much for help and patience guys. I'm sure I'll be back with more
probs soon!
Jul 23 '05 #10

P: n/a
You got it exactly - I was thrown by the seemingly unrelated problem it
caused.

Ken Wilson wrote:
Squid Seven wrote:
OK, tell me if my logic here is good. I completely uninstalled Dev-C++
and deleted the directory it was in. Then I reinstalled it, reinstalled
all my libraries, and then tried to compile the program again, with the
same problem. This means that corrupt standard library header files,
specifically <string>, *can't* be the cause of the problem, correct? So
the problem must be in my code?

I am going to try good old-fashioned troubleshooting on my own code now
(though I can't imagine how changes there caused this problem), but I'm
hoping that someone can confirm for me that the measures taken above do
in fact confirm that the problem *is* in my own code.

That would indeed confirm it. I mispoke earlier when I said you
couldn't use 'using' as you did but, after some looking, you were right
in its useage.

These compilers are usually very robust. If it has never caused you a
problem why would it decide to suddenly and on code you've used before.
I almost always take the blame for compiler errors and rightfully so,
except when working with MS libraries.

You stated you busted up a bunch of code. All it takes is one
semicolon out of place and it can create anything from a single
compiler error, to a fistfull of them sometimes. This is a not
uncommon occurrence if you're cutting and pasting large amouts of text
a single character is easy to lose sight ot.

Jul 23 '05 #11

P: n/a
> I still don't understand how it led to that strange little error in a very
distant area of the app, but I'm just glad that I can resume getting
things done... after four hours of banging my head against my desk,
reinstalling my development suite and libraries from scratch, and scouring
the web for irrelevant posts.


One very important thing to remember is that sometimes compilers have real
trouble diagnosing what is wrong.

If a compiler issue an error message for line NNNN, examine the line in
question and also examine the previous lines as the error could lie there.
The compiler initially passed over the problem line because potentially it
might make syntactic sense. It wasn't until it got to line NNNN that it knew
something was wrong and complained.

And you might have to backtrack quite a bit if intervening lines amount to
comments. You are looking for the previous
declarations/defintions/statements that are not comments. See if they amount
to correct C++.

Stephen Howe


Jul 23 '05 #12

P: n/a
On Thu, 14 Jul 2005 20:11:49 -0400, Squid Seven
<te*********@squidseven.com> did courageously avow:
You got it exactly - I was thrown by the seemingly unrelated problem it
caused.

Ken Wilson wrote:
Squid Seven wrote:
OK, tell me if my logic here is good. I completely uninstalled Dev-C++
and deleted the directory it was in. Then I reinstalled it, reinstalled
all my libraries, and then tried to compile the program again, with the
same problem. This means that corrupt standard library header files,
specifically <string>, *can't* be the cause of the problem, correct? So
the problem must be in my code?

I am going to try good old-fashioned troubleshooting on my own code now
(though I can't imagine how changes there caused this problem), but I'm
hoping that someone can confirm for me that the measures taken above do
in fact confirm that the problem *is* in my own code.

That would indeed confirm it. I mispoke earlier when I said you
couldn't use 'using' as you did but, after some looking, you were right
in its useage.

These compilers are usually very robust. If it has never caused you a
problem why would it decide to suddenly and on code you've used before.
I almost always take the blame for compiler errors and rightfully so,
except when working with MS libraries.

You stated you busted up a bunch of code. All it takes is one
semicolon out of place and it can create anything from a single
compiler error, to a fistfull of them sometimes. This is a not
uncommon occurrence if you're cutting and pasting large amouts of text
a single character is easy to lose sight ot.


You are in good company. I would venture, except for the very
exceptional student, we've all been down this road or one similar. I
remember too long chasing down a pointer problem I thought I had
fixed. A fellow student could hear me muttering under my breath and
after watching a few minutes said "Shouldn't you recompile that before
trying to run it again?" Doh.
Ken Wilson
"Just because people don't understand you doesn't mean
you are an artist"
Jul 23 '05 #13

P: n/a
Ken Wilson wrote:
On Thu, 14 Jul 2005 20:11:49 -0400, Squid Seven
<te*********@squidseven.com> did courageously avow:
You got it exactly - I was thrown by the seemingly unrelated
problem it caused.
You are in good company. I would venture, except for the very
exceptional student, we've all been down this road or one similar. I
remember too long chasing down a pointer problem I thought I had
fixed. A fellow student could hear me muttering under my breath and
after watching a few minutes said "Shouldn't you recompile that before
trying to run it again?" Doh.

I just did something like that recently. Trying to debug a program,
making changes, now the debugger seems off. Tried adding print
statements, those didn't work, frustrating. Then somebody points out
I'm rebuilding a different project than the one I'm debugging. As it
was embedded program loaded onto a target board, it didn't detect that
the target image wasn't up-to-date. Grrrrrrrrr.

Brian
Jul 23 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.