here is an example of my code:
#include <queue>
class GameBoard{
private:
queue<int> upcomingPieces;
};
Edited by becklighter, 14 August 2011 - 04:24 PM.
Posted 14 August 2011 - 04:18 PM
#include <queue>
class GameBoard{
private:
queue<int> upcomingPieces;
};
Edited by becklighter, 14 August 2011 - 04:24 PM.
Posted 14 August 2011 - 04:22 PM
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:#include <queue> class GameBoard{ private: queue<int> upcomingPieces; }
#include <queue>
class GameBoard{
private:
queue<int> upcomingPieces;
}; // <---
Posted 14 August 2011 - 04:26 PM
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:#include <queue> class GameBoard{ private: queue<int> upcomingPieces; }#include <queue> class GameBoard{ private: queue<int> upcomingPieces; }; // <---
Posted 14 August 2011 - 06:05 PM
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:#include <queue> class GameBoard{ private: queue<int> upcomingPieces; }#include <queue> class GameBoard{ private: queue<int> upcomingPieces; }; // <---
#include <queue>
class GameBoard{
private:
std::queue<int> upcomingPieces; // <-- std::
};
Posted 15 August 2011 - 02:24 AM
....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
Posted 15 August 2011 - 02:28 AM
A standard C++ rule, that's in almost every C++ style guide I've ever read is: Never use a "using namespace" statement globally in a header.std is used with vector, string,list,etc.... so putting std:: everywhere is not very elegant
#include "windows.h" #include <algorithm> int a = 2, b = 4; int c = std::max( a, b );//compile error - windows contains a #define max line!!!
#include <queue>
class queue{};
queue q;//makes my queue, not a std::queue
std::queue<int> q2;//makes a std::queueNow, if we include a header that has rudely used "using namespace" inside it:#include "Adaline.h" // includes "using namespace std;"
#include <queue>
class queue{};
queue q; // compile error? This code was fine a minute ago?!! thanks Adaline ;)
std::queue<int> q2;//Adaline.h
#include <queue>
namespace adaline
{
using namespace std;//ok, you've only polluted your own namespace
}The concept extends beyond the std namespace.Isn't it a bad idea to call a class 'string' anyway ?
Posted 15 August 2011 - 02:33 AM
Thanks for you're explanation (I mean it)A standard C++ rule, that's in almost every C++ style guide I've ever read is: Never use a "using namespace" statement globally in a header.std is used with vector, string,list,etc.... so putting std:: everywhere is not very elegant
It pollutes the global namespace in the same way that #defines do, which is something that namespaces were designed to avoid.
e.g. this is the problem with defines:#include "windows.h" #include <algorithm> int a = 2, b = 4; int c = std::max( a, b );//compile error - windows contains a #define max line!!!
Now, namespaces solve these kinds of problems for us.
Here is some perfectly valid code:#include <queue> class queue{}; queue q;//makes my queue, not a std::queue std::queue<int> q2;//makes a std::queueNow, if we include a header that has rudely used "using namespace" inside it:#include "Adaline.h" // includes "using namespace std;" #include <queue> class queue{}; queue q; // compile error? This code was fine a minute ago?!! thanks Adaline! std::queue<int> q2;
If you really do want to use "using namespace" in a header, then you must at least always wrap it in your own namespace, e.g.//Adaline.h #include <queue> namespace adaline { using namespace std;//ok, you've only polluted your own namespace };