Jump to content
  • Advertisement
Sign in to follow this  
Mizipzor

Class constructors before the constructor

This topic is 4861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ive got a Game class, the class that holds all the other classes used and handles the communication between them. The other classes needs arguments for thier constructors, but how do I supply them when the classes are created at the same time as the game class itself? I was told I need to do this: Game::Game() : sdl( RESX, RESY, 32 ) { The sdl class handle graphics, it needs the x and y resolution. But how do I add a second one after that? I tried this: Game::Game() : sdl( RESX, RESY, 32 ) : AsciiMap( RESX / GRIDSIZE, RESY / GRIDSIZE) { But it didnt work, getting many errors of the type: error C2601: 'Game::MainLoop' : local function definitions are illegal For all functions in the game class. How do I do it? Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
You need commas to separate each item in the initializer list.
Game::Game() : sdl( RESX, RESY, 32 ), AsciiMap( RESX / GRIDSIZE, RESY / GRIDSIZE)
{
}

Share this post


Link to post
Share on other sites
Thanks, couldnt find it in the MSDN... msdn isnt good when you want to find out very basic stuff. Thanks anyways guys :)

Share this post


Link to post
Share on other sites
MSDN is a library reference, so it assumes you know the language syntax. Anyway, the operative word here is initializer list; it's the same as a parameter list - it's comma-separated.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!