# Class constructors before the constructor

## 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 on other sites
You need commas to separate each item in the initializer list.
Game::Game() : sdl( RESX, RESY, 32 ), AsciiMap( RESX / GRIDSIZE, RESY / GRIDSIZE){}

##### 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 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.