• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
becklighter

adding a queue to a class

12 posts in this topic

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
0

Share this post


Link to post
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]
[/quote]

[code]
#include <queue>

class GameBoard{
private:
queue<int> upcomingPieces;
}; // <---
[/code]
0

Share this post


Link to post
Share on other sites
[quote name='NumberXaero' timestamp='1313360569' post='4849144']
[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]
[/quote]

[code]
#include <queue>

class GameBoard{
private:
queue<int> upcomingPieces;
}; // <---
[/code]
[/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?
0

Share this post


Link to post
Share on other sites
[quote name='NumberXaero' timestamp='1313360569' post='4849144']
[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]
[/quote]

[code]
#include <queue>

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

and

[code]
#include <queue>

class GameBoard{
private:
std::queue<int> upcomingPieces; // <-- std::
};
[/code]
0

Share this post


Link to post
Share on other sites
Hello :)

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

Share this post


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

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

Share this post


Link to post
Share on other sites
[quote name='Adaline' timestamp='1313396366' post='4849289']
[quote name='rip-off' timestamp='1313394843' post='4849284']
....as there is no way to "un-use" a namespace.
[/quote]

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


"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 [i]after[/i] all headers are included, and then only as absolutely necessary.

2

Share this post


Link to post
Share on other sites
What about inline classes ? Where else could you put the using directive ? Isn't it a bad idea to call a class 'string' anyway ?
0

Share this post


Link to post
Share on other sites
[quote name='Adaline' timestamp='1313396366' post='4849289']std is used with vector, string,list,etc.... so putting std:: everywhere is not very elegant[/quote]A standard C++ [url="http://stackoverflow.com/questions/5849457/using-namespace-in-c-headers"]r[/url][url="http://stackoverflow.com/questions/6077566/using-namespace-std"]u[/url][url="http://stackoverflow.com/questions/4872373/why-is-including-using-namespace-into-a-header-file-a-bad-idea-in-c"]l[/url][url="http://nepsweb.co.uk/pgtcpp/namespace.htm"]e[/url], that's in almost every C++ style guide I've ever read is: [b]Never use a "using namespace" statement globally in a header[/b].

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:[code]#include "windows.h"
#include <algorithm>
int a = 2, b = 4;
int c = std::max( a, b );//compile error - windows contains a #define max line!!![/code]

Now, namespaces solve these kinds of problems for us.
Here is some perfectly valid code:[code]#include <queue>
class queue{};
queue q;//makes my queue, not a std::queue
std::queue<int> q2;//makes a std::queue[/code]Now, if we include a header that has rudely used "using namespace" inside it:[code]#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;[/code]

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.[code]//Adaline.h
#include <queue>
namespace adaline
{
using namespace std;//ok, you've only polluted your own namespace
}[/code]
[quote name='Adaline' timestamp='1313396893' post='4849291']Isn't it a bad idea to call a class 'string' anyway ?[/quote]The concept extends beyond the [font="Courier New"]std[/font] 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.
2

Share this post


Link to post
Share on other sites
[quote name='Hodgman' timestamp='1313396905' post='4849292']
[quote name='Adaline' timestamp='1313396366' post='4849289']std is used with vector, string,list,etc.... so putting std:: everywhere is not very elegant[/quote]A standard C++ [url="http://stackoverflow.com/questions/5849457/using-namespace-in-c-headers"]r[/url][url="http://stackoverflow.com/questions/6077566/using-namespace-std"]u[/url][url="http://stackoverflow.com/questions/4872373/why-is-including-using-namespace-into-a-header-file-a-bad-idea-in-c"]l[/url][url="http://nepsweb.co.uk/pgtcpp/namespace.htm"]e[/url], that's in almost every C++ style guide I've ever read is: [b]Never use a "using namespace" statement globally in a header[/b].

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:[code]#include "windows.h"
#include <algorithm>
int a = 2, b = 4;
int c = std::max( a, b );//compile error - windows contains a #define max line!!![/code]

Now, namespaces solve these kinds of problems for us.
Here is some perfectly valid code:[code]#include <queue>
class queue{};
queue q;//makes my queue, not a std::queue
std::queue<int> q2;//makes a std::queue[/code]Now, if we include a header that has rudely used "using namespace" inside it:[code]#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;[/code]

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.[code]//Adaline.h
#include <queue>
namespace adaline
{
using namespace std;//ok, you've only polluted your own namespace
};[/code]
[/quote]
Thanks for you're explanation (I mean it)
No need to be rude anyway
2

Share this post


Link to post
Share on other sites
[quote name='Adaline' timestamp='1313397192' post='4849293']No need to be rude anyway[/quote]Sorry if I came across as rude! Just trying to get to the point [img]http://public.gamedev.net/public/style_emoticons/default/wink.gif[/img]
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0