Global static variables
Soeren Grimm
soeren@viatronix.net
Fri May 18 07:51:00 GMT 2001
Hi,
i don't know where i exactly should ask this. By i think may be this is
the
right mailinglist.
We have a huge project with different modules. So we wanna make our own
output-stream.
Like std::out, but with special features. But for this we must somehow
ensure that there is only ONE instance of the outputstream in the whole
project.
We tried:
1.)
global.h:
static outputsteam dbg;
2.)
global.h:
extern outputstream dbg,
global.cpp:
outputstream dbg
======================
Then we include global. h in all files.
Problem of solution 1: multiple instance of dbg;
Problem of solution 2: we can't ensure that the instance is constructed
in time.
The outputstream itself could be used in constructors of other classes.
What is the right way to define something really global and only once?
Thanks in advance
regards,
Soeren
More information about the Gcc
mailing list