class with custom constructor, within another class

Hi, I'm having trouble calling the constructor of a class within another class, that accepts some arguments in its constructor. Actually I got it working if I put it on the heap, but for some reason not so well as a normal stack class.

here is the constructor declaration:

1
2
3
CFinalQuestion::CFinalQuestion(Uint8 myState,
                               Uint8 QuitState1,
                               Uint8 QuitState2);


and here is the attempt within the other class:

1
2
3
4
5
6
7
8
class Game
{

CFinalQuestion FinalQuestion(1, 2, 2);

...

};


the compiler error (Using MingW) is as follows:

handler.h|147|error: expected identifier before numeric constant|
handler.h|147|error: expected ',' or '...' before numeric constant| 


If anyone knows how to do this properly, I'd be thankful for the insight; thanks in advance! -B
You can't initialize an object in the class declaration. You do that in the class ctor
1
2
3
4
5
6
7
8
class Game
{

CFinalQuestion FinalQuestion;

...

};

1
2
3
4
Game::Game() : FinalQuestion(1, 2, 2)
{
  ...
}
Thanks, the initializer works very well. -B
Topic archived. No new replies allowed.