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

Standard c++ help

8 posts in this topic

Hello.
I am trying to declare a class"Application" and inside this class"Application" make a object of class "Airplane" and "Airplane" constructor takes reference object of class "Application" how to make that?

Exzample:

[CODE]
"Airplane.h"
class Application;
class Airplane
{
public:
Airplane(Application& objApp);
int wings;
};

"Application.h"
#include "Airplane.h"
class Application
{
public:
Airplane objectofAirplane (*this);
};
[/CODE]

Youtube is crashing so hard. Cant get to tutorials, cant even see how to define this

Basically what i am trying to achieve is to call a function from class "Application" in "Airplanes constructor".
Now i don't think this is possible but... worth asking. Edited by BaneTrapper
1

Share this post


Link to post
Share on other sites
[quote name='Brother Bob' timestamp='1351720559' post='4995961']
Assuming that is your exact code, then the primary problem is that you cannot both define and initialize members of a class like that. You have to initialize them in the constructor's initializer list.

The secondary problem, once the above is "solved", is that you should be very careful when you pass [i]this [/i]to a member's constructor. The member's constructor is executed before [i]Application[/i]'s constructor, so the [i]Application [/i]object you're passing to the [i]Airplane[/i]'s constructor is not fully constructed yet. I don't know if it is outright undefined, or simply just undefined to touch the parts that has yet to been initialized so that you can arrange the member carefully to avoid accessing uninitialized parts.

The tertiary problem is (or rather, may be) a design problem: why does the [i]Airplane [/i]have to know about the [i]Application[/i]?
[/quote]

[quote name='Brother Bob']
so the Application object you're passing to the Airplane's constructor is not fully constructed yet
[/quote]
That's why i stated i think its impossible this way.

Well the reason i was trying to pass it this was is the reason i need to call "Airplane::SetAirplane(All the variables);
Example: Am passing pointers to something like "MousePosX" and am thinking a way around from calling a Set function

I decided not to waste too much time here, a whole game needs to be made.
A good day sir's. Edited by BaneTrapper
0

Share this post


Link to post
Share on other sites
The fundamental design problem here is that the aeroplane is assuming too much knowledge of its environment. To decouple the classes, instead of having the aeroplane ask about the position of the mouse, let the application notify the aeroplane when the mouse changes.

Going even further, aeroplanes don't need to know about mice. They need trajectory changes or targets. So the application can just inform the aeroplane that the user has adjusted its orientation, or that the user has clicked on a new target, or whatever (depending on the nature of your game). This also makes it easier later on if you decide to support alternative input methods, for instance a joystick.
1

Share this post


Link to post
Share on other sites
[quote name='SiCrane' timestamp='1351744081' post='4996068']
[quote name='Brother Bob' timestamp='1351720559' post='4995961']
Assuming that is your exact code, then the primary problem is that you cannot both define and initialize members of a class like that. You have to initialize them in the constructor's initializer list.[/quote]
This changes with C++11, which allows [i]brace-or-equal-initializers[/i] for member variables. Though as the name suggests you need to use either braces or = in order to specify out of constructor initializers. However, not as many compilers as I would like support this syntax now.
[/quote]
I thought that way of initializing members was only allowed for compile-time or constant expressions, or perhaps even expressions with members that has been initialized already, since you cannot pass any parameters (unless you want to correct me again). That would make it useless in this particular case. But seems like [i]this[/i] is indeed allowed, and that makes sense also, so there you go: +1 for that.
1

Share this post


Link to post
Share on other sites
I'm not sure what you mean by "cannot pass any parameters". If you are saying that you can't pass any of the parameters from a constructor to a brace-or-equal-initializer, then no, the you can't. The class member initializers are used in the default case, if no member initializers are used for that member in a constructor's member initialization list. However, that's not what the code in the OP was doing. Otherwise, class member initializers have no restrictions on the complexity of the expressions used as initializers for non-constexpr member variables that I can find in the standard (admittedly, the semantics for brace-or-equal-initializers are spread out over something like five different sections so I may I have missed one). In particular, member functions are explicitly fair game as it talks about how virtual functions called work just like other virtual functions called in constructors and the class is specifically noted to be a completed type within the scope of a brace-or-equal-initializer so any expression involving any of the class' member variables are also fair game (unfortunately, this also means members that haven't been constructed yet).
1

Share this post


Link to post
Share on other sites
As you said, I meant that you cannot (as I understood it) get any parameters from the constructor to the initializer. I just thought that there's not a lot you can do other than giving a default value, given that you cannot compute anything object-specific that needs object-specific parameters you typically pass to the constructor. However, they seem to be more a bit more flexible then I had first assumed.
1

Share this post


Link to post
Share on other sites
I suppose you could pass parameters indirectly. You could have the constructor initialize a member variable using parameters and then reference that member variable in the initializers for other member variables. Ex: constructor initializes a count variable and the member initializer allocates memory based on that count. I wouldn't want to maintain that kind of code, but I don't think there's anything in the standard to prevent it.
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