This topic is now archived and is closed to further replies.


Globalize my own class objects...

Recommended Posts

Hi, Been playing around more with my first bomberman game engine. I noticed that when I want to globally (putting it just a little below the header includes with the DirectDraw stuff) declare some objects of classes that I created I can''t and get this error: Compiling... engine.cpp engine.cpp(45) : error C2143: syntax error : missing '';'' before ''.'' engine.cpp(45) : error C2501: ''g_map'' : missing storage-class or type specifiers engine.cpp(45) : error C2371: ''g_map'' : redefinition; different basic types engine.cpp(44) : see declaration of ''g_map'' engine.cpp(45) : error C2143: syntax error : missing '';'' before ''.'' Error executing cl.exe. Engine.exe - 4 error(s), 0 warning(s) Basically, this error will be gone if I decide to declare my map objects within a function, such as the main loop. But this doesn''t make sense because I don''t want a new map on every loop right? I have a Constructor that takes the map width and height, a destructor which properly deletes allocated memory and a copy constructor that can do deep copies defined (2d arrays). What am I doing wrong? Thanks!

Share this post

Link to post
Share on other sites
Sorry bout that hehe

// Bitmap surfaces used for blitting
// Map bitmaps
CSurface *g_WallBit = NULL; // Wall tile bitmap
CSurface *g_PathBit = NULL; // Path tile bitmap
CSurface *g_BlockBit = NULL; // Block tile bitmap

// Player bitmaps
CSurface *g_UpBit = NULL; // Up bitmap
CSurface *g_DownBit = NULL; // Down bitmap
CSurface *g_RightBit = NULL; // Right bitmap
CSurface *g_LeftBit = NULL; // Left bitmap
CSurface *g_DudeBit = NULL;// Dude bitmap

<============== this first part to let you see where I placed my global game elements, right below directdraw stuff

// Global game elements
int g_mapSize = 7;
static BomberMap g_map = BomberMap(g_mapSize,g_mapSize); // Create a 7x7 map grid
g_map.GenerateStandardMap(); // Set tiles in there
int g_tileSpace = 64; // Tile spacing value used to draw tiles properly

Share this post

Link to post
Share on other sites
Thanks for your reply. For some reason pointers did the trick. I tried your method and it worked but for some reason the default zero data was initialized in there. Must be something wrong wth my copy constructor. Hmmmm.

Share this post

Link to post
Share on other sites