OK... People do NOT do it this way in C++. In *C++* people do
struct GlobalStruct
{
int x;
short something_else;
};
The 'typedef' dance is only needed in C and only if you want to
use 'GlobalStruct' without the keyword 'struct' in front of it.
You have to forgive me here. Although I didn't mention this, where I
work, they make it mandatory to declare structures with a typedef. I
have tried but it seems to me that if they feel a particular way of
doing something is more idealogical than actually yielding any
practical benefits, anything I say just falls into deaf ears.
Why have a pointer along with the object. Why not simply have
the object? Also, if you really want something *global*, I would
still prefer
struct GlobalStruct
{
static int x;
static short something_else;
};
(in the header), and then
int GlobalStruct::x;
short GlobalStruct::something_else;
in your 'globals.cpp' file. At least then you can access the
variables using true "global" syntax:
int b = GlobalStruct::x;
instead of the obscure
int b = gs->x;
This is exactly what I had in mind. The example I posted was snipped
out of some open source code I saw on the internet. That kind of
doing things seems to be prevalent in many OSS codebases I checked in
my few minutes of googling. Hence my query as to what is recommended
*C++* way of doing things.
Whatever helps you achieve what you set out to achieve.
I am not an expert in C++ -- I only have an above average
understanding of the language. Despite that most times I am always
sitting on a fence over the **C++** way of doing things as opposed to
plodding on with the first thing that comes to my mind.
Hence my trivial queries!