global class throughout project
hello , im back with another problem.
im trying to setup a class and an associated struct for global access throughout my project. I have a common.h included in all my headers to which in this I have the struct "con_var" ... my console variable structure. I need this global as they will be everywhere, and I also need have a ''project global'' class (conmanager) that manages these as well.
There seems to be a bit of a loop over where I declare in common.h the con_var struct for conmanager.h and (vise versa) my ''extern conmanager'' for in common.h (for my proj global manager)
Im confuesed as to where to declare my manager I think its suppose to me in a cpp and then to put an extern into the common.h so its global throughout the project ( I declared it in common.c )
can someone clarify my predicament pleaseeeeeeeeeeee
thanks
//game.cpp#include "global.h"cout << globalint; //global.cpp#include "global.h"int globalint = 0; //global.h#ifndef GLOBAL_H#define GLOBAL_Hextern globalint;#endif
is that what you want?
Edited by - evilcrap on January 15, 2002 10:15:24 PM
no , but thats how I understand to do.
but my predicament is that I have a class conmanager that has a list of cvars ... hmm in code this might looke a bit better.
the problem is in the headers ... to have a global cvarmgr I need to include the header to get at the structure. Im gather this is a catch 22 situation and one of the things your not suppose to do in C++.
But what are the other options .... declare all project globals in Main and then pass them around and around having huge parameters ? *(not that i mind im just saying )
*hmmm maybye I should start looking at c++ game code rather than quake and quake 2 *
but my predicament is that I have a class conmanager that has a list of cvars ... hmm in code this might looke a bit better.
/////////globals.h/////////////////////////#include cvarmgr.h // proving a loop between global.h // and cvarmgrstruct cvar_s{ char *name; char *string float value;}cvar_t; // global console variable declarationextern cvarmgr_t *cvar_vars; // our "project global" console varable manager///////////globals.cpp ///////////////////cvarmgr_t *cvar_vars // our declaration//////////// cvarmgr.h///////////////////#include "globals.h // loop class cvarmgr_t{ vector<cvar_s> list;}
the problem is in the headers ... to have a global cvarmgr I need to include the header to get at the structure. Im gather this is a catch 22 situation and one of the things your not suppose to do in C++.
But what are the other options .... declare all project globals in Main and then pass them around and around having huge parameters ? *(not that i mind im just saying )
*hmmm maybye I should start looking at c++ game code rather than quake and quake 2 *
To avoid that both files depend on each other make a forward declaration. Then you won''t have the need to include whatever.h in global.h.
// global.h
class xyz; // The forward declaration
extern xyz theGlobalThing;
By making a forward declaration you tell the compiler that it is ok to define variables of this type and that you''ll tell him later what exactly this class is. By doing so you have no need to include your classXYZ.h and the project should compile without (this ;-)) error.
// global.h
class xyz; // The forward declaration
extern xyz theGlobalThing;
By making a forward declaration you tell the compiler that it is ok to define variables of this type and that you''ll tell him later what exactly this class is. By doing so you have no need to include your classXYZ.h and the project should compile without (this ;-)) error.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement