Hello all.
I know it aint the prettiest way of doing things, but I've got two big namespaces in our project - one for global variables; one for global types/enums/structs..
I'm basically wondering if the following is the right way of doing things... It all seems to compile fine, so I guess it isn't *wrong*, but is it *correct*!!
For global variables
nsVars.cpp
namespace MyNameSpaceVars {
int iGlobal1;
int iGlobal2;
}
nsVars.h
namespace MyNameSpaceVars {
extern int iGlobal1;
extern int iGlobal2;
}
Then, where any other module requires to read/write said globals, it #include's nsVars.h and then access it through MyNameSpaceVars::iGlobal1...
For GLOBAL structs/types/enums
Now this is the part that doesn't look so pretty, yet seems to work:
nsTypes.h
namespace MyNameSpaceTypes {
struct Vec3D {
float x;
float y;
float z;
}
enum GAME_STATE {
GS_INTRO = 1,
GS_MENU = 2,
GS_GAME = 3
}
}
and then anything that needs to declare/use the respective contents just #include's nsTypes.h and is declared:
MyNameSpaceTypes::Vec3D myVector;
myVector.x = 1; //and so on
Now, its the enum's I don't like so much:
void SomeFunc( MyNameSpaceTypes::GAME_STATE gs ) {
switch ( gs ) {
case MyNameSpaceTypes::GS_INTRO:
//do stuff when the intro is in progress
break;
case MyNameSpaceTypes::GS_MENU:
//do stuff while user is in menu
break;
case MyNameSpaceTypes::GS_GAME:
//do stuff when in game
break;
}
}
This works / compiles. But accessing the values for the 'GAME_STATE' enum through the 'MyNameSpaceTypes' accessor seems less intuitive than using something like 'GAME_STATE::GS_MENU' or just 'GS_MENU' (I know I can get the latter by doing using namespace MyNameSpaceTypes; but I dont like doing it that way!)
Sorry for the long ramble, but I'd appreciate peoples thoughts
Best regards,
Jack
[edited by - Jollyjeffers on March 29, 2004 4:06:24 PM]