• 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
Waterlimon

Should i forward declare stuff in other namespaces?

8 posts in this topic

So, i need a reference to an object living in another namespace.

The setup is as such for the forward declaration:

namespace a
{
namespace c
{
class otherclass;
}
namespace b
{
class myclass
{
c::otherclass& other;
};
}
}

This works, but what i dont like is that if i were to lets say, change the namespace name or even location of the other class, i would need to create or rename a whole namespace there, in addition to changing any reference to it within myclass.

So, the question is, is the benefit from using a forward declaration high enough to have that extra namespace there. I would much prefer simply having to change the (currently) single reference to otherclass withing myclass if i were to change its location or namespace/class name, rather than also having to mess with the forward declaration.

Is the preprocessor/complier/whatever able to do the forward declaration "under the hood" somehow? Considering that im not writing a major 500k line project but a tiny hobby game, is the possible build time increase really that bad? If its not that bad, should i still use forward declarations when needed because its a good habit?

Lots of threads about fwd declarations lately btw.
0

Share this post


Link to post
Share on other sites
In general you should get into the habit of using forward declaration whenever you can get away with using only a forward declaration. However, that doesn't mean that you necessarily need to write out the forward declaration manually every time you need one. If a forward declaration gets complicated, such as being in a nested namespace or being a typedef for a template type, then you may want to consider using headers that just have forward declarations. Then include the forward declaration header rather than the full header. An example of this in the standard library is the iosfwd header which just has forward declarations for things like the stream classes.
2

Share this post


Link to post
Share on other sites
I also feel the need to ask, if the class which has this reference is a base class, and the forward declared class internals are used in the derieved class, should i in that case include the header, because if i do not i would need to include it in the derieved class anyways, and the derieved class might not know what header the class resides in? I assume the answer for this is that i shouldnt use forward declarations in this case.<br /><br />I would have edited the original post but i dont feel like respacing it because it always gets messed up when i edit...
0

Share this post


Link to post
Share on other sites
It's not clear to me what kind of situation you're talking about. Can you give an code example?
0

Share this post


Link to post
Share on other sites
Take the example in my first post, and imagine that the reference is lets say the return type of an abstract virtual function.<br /><br />As such the base class (that example class) only needs a forward declaration, but the derieved class however needs the full definition because it needs to implement the virtual function.<br /><br />If i only have a forward declaration in the base class header, i will need to include the full header in the derieved class, which feels wrong.
0

Share this post


Link to post
Share on other sites
I don't see how that's different from any other forward declaration situation: you use a forward declaration when you can get away with it and use the full definition when you need it. And if you have a separate header for the derived class's definition and a source file for the member function implementations then you only need the full definition in the source file, which is exactly the same as the usual forward declaration in header and full header in source file situation for forward declarations.
0

Share this post


Link to post
Share on other sites
Its just that in this case, anything derieving from the class will most likely need the definition, so wouldnt it make sense to include it in the base class header?

In this case the derieved class is told that a class named like this exists, if i dont include it in the base class header the writer of the derieved class needs to go hunting for the right header.

I think the difference with "normal" forward declarations is that in those cases the actual object is passed from outside, leading me to believe that the outside must already have the definition and doesnt need to figure out where to find it based on an incomplete declaration.
0

Share this post


Link to post
Share on other sites
I don't see how this is any different from a "normal" forward declaration situation. If a caller or implementer needs the full definition then the can include the right header. If they don't then there's no reason to force them to be dependent of the header for the full definition.
0

Share this post


Link to post
Share on other sites
Yeah i guess i should just keep the forward declaration...

This is for a base class which i plan to derieve many classes from, and those classes have a virtual method that returns a reference to an object of type X, and i expect each to fill X with the right data, so it felt natural to have the header in the base.

But there is the possibility of the derieved class getting that data from outside so the forward declaration is likely better.
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