Sign in to follow this  
Mizipzor

Class constructors before the constructor

Recommended Posts

Mizipzor    247
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
Agony    3452
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
Mizipzor    247
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
Zahlman    1682
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

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