Jump to content

View more

Image of the Day

Inventory ! Va falloir trouver une autre couleur pour le cadre D: #AzTroScreenshot #screenshotsaturday https://t.co/PvxhGL7cOH
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

adding a queue to a class

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
12 replies to this topic

#1 becklighter   Members   

138
Like
0Likes
Like

Posted 14 August 2011 - 04:18 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;

};


Edited by becklighter, 14 August 2011 - 04:24 PM.


#2 NumberXaero   Prime Members   

2607
Like
0Likes
Like

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;
};  // <--- 


#3 becklighter   Members   

138
Like
0Likes
Like

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;
};  // <--- 


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?

#4 Wooh   Members   

1088
Like
0Likes
Like

Posted 14 August 2011 - 04:29 PM

It's called std::queue

#5 DoctorGlow   Members   

1774
Like
0Likes
Like

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;
};  // <--- 


and

#include <queue>

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


#6 Tournicoti   Prime Members   

704
Like
-1Likes
Like

Posted 15 August 2011 - 01:47 AM

Hello :)

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


#7 rip-off   Moderators   

10892
Like
1Likes
Like

Posted 15 August 2011 - 01:54 AM

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

#8 Tournicoti   Prime Members   

704
Like
0Likes
Like

Posted 15 August 2011 - 02:19 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

#9 ApochPiQ   Moderators   

22551
Like
2Likes
Like

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



"using" a namespace in a header is bad.

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.


Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

#10 Tournicoti   Prime Members   

704
Like
0Likes
Like

Posted 15 August 2011 - 02:28 AM

What about inline classes ? Where else could you put the using directive ? Isn't it a bad idea to call a class 'string' anyway ?

#11 Hodgman   Moderators   

50629
Like
2Likes
Like

Posted 15 August 2011 - 02:28 AM

std is used with vector, string,list,etc.... so putting std:: everywhere is not very elegant

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.

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::queue
Now, 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
}

Isn't it a bad idea to call a class 'string' anyway ?

The concept extends beyond the std namespace.
Maybe I'm using two different bits of C++ middleware that both define a Vector3 type? If I using-namespace'd them, I'd get conflicts between the two libraries.

#12 Tournicoti   Prime Members   

704
Like
2Likes
Like

Posted 15 August 2011 - 02:33 AM

std is used with vector, string,list,etc.... so putting std:: everywhere is not very elegant

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.

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::queue
Now, 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
};

Thanks for you're explanation (I mean it)
No need to be rude anyway

#13 Hodgman   Moderators   

50629
Like
0Likes
Like

Posted 15 August 2011 - 02:35 AM

No need to be rude anyway

Sorry if I came across as rude! Just trying to get to the point Posted Image




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.