Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error while compilation

Status
Not open for further replies.

sab1234

Programmer
Sep 29, 2003
11
0
0
US
I am trying to compile a C++ application on HP-UX11.11. I am using gcc-3.3.1. I am getting the following error while compilation:

/usr/local/bin/pa20_32/include/c++/3.3.1/backward/queue.h:34: error: `queue'is already declared in this scope

Can anyone please help me on this.

Thanks
-Anand.
 
If you don't use namespaces, somewhere in your application you already have a class, structure or global variable (yuk) named 'queue' and the compiler can't tell which is which.
If you do use namespaces, the same has happened, only within a namespace other than the global one.

Regards,
Bert Vingerhoets
vingerhoetsbert@hotmail.com
Don't worry what people think about you. They're too busy wondering what you think about them.
 
Thanks for the reply Bert

I have used

using namespace std;

in my code.

I am new to programming and does not have much idea. Can you please help me out. I can send you the entire code if you want for reference.

Thanks,
Andy



 
Is 'queue' something you have defined yourself? It sometimes happens that a class/struct/variable gets #included twice, because of the nature of the file dependencies, e.g. you #include various files, but two of these in turn #include some common file.

If this is the case, you can get round it as follows:

queue.h:
--------

Code:
#ifndef _ANAND_QUEUE  //  stands for "if not defined"
#define _ANAND_QUEUE

... your definition of 'queue' etc. ...

#endif

otherfile1.h
------------

Code:
#include "queue.h"  // Works as normal
....

otherfile2.h
------------

Code:
#include "queue.h"  // Works as normal
....

main.cpp
--------

Code:
#include "otherfile1.h" // Includes definition of 'queue'
#include "otherfile2.h" // Ignores second definition of 'queue'


It's good practice to do this in all header files you write; it can never hurt, even if it's not the solution to your particular problem.

Something similar is done in standard include files, so they shouldn't cause problems. If they do, it's more likely a name-clash between different classes/variables whose names happen to be the same. In this case, qualify one or both with:

Code:
#include <something>
using namespace first;

#include <somethingelse>
using namespace second;

Hope this helps,

tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top