Problem creating an instance of a class inside another's header

I've created a dynamic '2d' array as a class, which I want to create an instance of in another class (the main game class for a 'connect 4' - where the grid size can be changed)
The problem arrizes that if i create the instance in the header of the game file so that all the class can use it..then it won't let me input the grid parameters
e.g.
1
2
    DynamicMultiDim GridArray; //this works
    DynamicMultiDim GridArray(COLUMNS, ROWS, GOAL); /* but if i try this with the appriopriate constructor in DynamicNultiDim i get errors*/

The error I get is expected ';' before '(' token...
I get this because COLUMNS ROWS and GOAL havent been given values yet: this happens in the the implementation of the games constructor... I tried doing this in the header but it made no difference :(

If I create the instance of the dynamic multi dim array inside the games constructor in the .cpp it works because the COLUMNS ROWS and GOAL variables have been given values there but the instance isnt accessable/deffined to/for the rest of the class.. I guess it goes out of scope with the constructor.

Any suggestions are welcome :)
Don't initialize globals in headers. Do it in a cpp:
1
2
3
4
5
//a.h
extern T global;
//a.cpp
#include "a.h"
T global(/*...*/);

It's odd, though. That should give you a linker error, not a compiler error.
Thanks, thats great.
Topic archived. No new replies allowed.