• 10
• 9
• 12
• 14
• 14

# adding a queue to a class

This topic is 2445 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm attempting to add a queue as a private member of my class, but get the error " syntax error : missing ';' before '<' " on the line where it is declared, I would appreciate any insight into why I'm unable to compile.

here is an example of my code:
[source]
#include <queue>

class GameBoard{
private:
queue<int> upcomingPieces;
};
[/source] Edited by becklighter

##### Share on other sites

I'm attempting to add a queue as a private member of my class, but get the error " syntax error : missing ';' before '<' " on the line where it is declared, I would appreciate any insight into why I'm unable to compile.

here is an example of my code:
[source]
#include <queue>

class GameBoard{
private:
queue<int> upcomingPieces;
}
[/source]

 #include <queue> class GameBoard{ private: queue<int> upcomingPieces; }; // <--- 

##### Share on other sites

[quote name='becklighter' timestamp='1313360304' post='4849142']
I'm attempting to add a queue as a private member of my class, but get the error " syntax error : missing ';' before '<' " on the line where it is declared, I would appreciate any insight into why I'm unable to compile.

here is an example of my code:
[source]
#include <queue>

class GameBoard{
private:
queue<int> upcomingPieces;
}
[/source]

 #include <queue> class GameBoard{ private: queue<int> upcomingPieces; }; // <--- 
[/quote]

Thanks for pointing out that my class was missing the ";", but that isn't the problem. The code in my project actually had that part right, I just didn't copy it all over, any other ideas?

##### Share on other sites
It's called std::queue

##### Share on other sites

[quote name='becklighter' timestamp='1313360304' post='4849142']
I'm attempting to add a queue as a private member of my class, but get the error " syntax error : missing ';' before '<' " on the line where it is declared, I would appreciate any insight into why I'm unable to compile.

here is an example of my code:
[source]
#include <queue>

class GameBoard{
private:
queue<int> upcomingPieces;
}
[/source]

 #include <queue> class GameBoard{ private: queue<int> upcomingPieces; }; // <--- 
[/quote]

and

 #include <queue> class GameBoard{ private: std::queue<int> upcomingPieces; // <-- std:: }; 

##### Share on other sites
Hello

There are 2 options :
• use std::queue instead of queue everywhere
• or [s]put using namespace std; after the #include<queue>[/s] (sorry )

##### Share on other sites
It is advised against putting using directives in header files, as there is no way to "un-use" a namespace.

##### Share on other sites

....as there is no way to "un-use" a namespace.

Why would you 'un-use' a namespace ?
std is used with vector, string,list,etc.... so putting std:: everywhere is not very elegant

##### Share on other sites

[quote name='rip-off' timestamp='1313394843' post='4849284']
....as there is no way to "un-use" a namespace.

Why would you 'un-use' a namespace ?
std is used with vector, string,list,etc.... so putting std:: everywhere is not very elegant
[/quote]

What if I want to call something foo::string? If I #include your header, I now have a name collision between foo::string and std::string.

You should only be "using" namespaces from within .cpp files, preferably after all headers are included, and then only as absolutely necessary.