Y
YUY0x7
I'm writing because I was having a little problem implementing one of
the designs suggested in Modern C++ Design. The one I'm talking about
is that of the class factory which registers classes using identifiers.
My problem goes like this:
I am developing a game engine and I am using that method to register
my game entity classes with a generic class factory. Each class has a
unique integer ID. The singleton class factory is in a static library
along with the (basic) classes I want to register (of course I want to
allow other classes in other libraries to be registered too, e.g
game-specific classes). I register the classes as it was suggested,
with
a line similar to the following in each of the classes source file:
static const bool registered =
SomeClassFactory::Instance().Register<SomeClass>(some_id);
Alright. Everything seems fine with this, but apparently not. Some
classes get registered and some don't. I've pinpointed the problem to
be that only the classes which I reference some function(s) in their
source file, get registered. The others don't even call Instance() nor
Register(). I thought that every static global variable got
initialized regardless of their usage afterwards. Is this not true?
Can I blame it on the compiler (I'm using vc++ 7.1 which is very good)
? When I go ahead and reference one function in the source file which
doesn't register the class, it now does register it.
I am trying this by linking the static library with my executable (a
game). Does static libraries have different global initialization
rules?
If you need any more information, please don't hestitate to ask.
Thanks a lot,
George Faraj
the designs suggested in Modern C++ Design. The one I'm talking about
is that of the class factory which registers classes using identifiers.
My problem goes like this:
I am developing a game engine and I am using that method to register
my game entity classes with a generic class factory. Each class has a
unique integer ID. The singleton class factory is in a static library
along with the (basic) classes I want to register (of course I want to
allow other classes in other libraries to be registered too, e.g
game-specific classes). I register the classes as it was suggested,
with
a line similar to the following in each of the classes source file:
static const bool registered =
SomeClassFactory::Instance().Register<SomeClass>(some_id);
Alright. Everything seems fine with this, but apparently not. Some
classes get registered and some don't. I've pinpointed the problem to
be that only the classes which I reference some function(s) in their
source file, get registered. The others don't even call Instance() nor
Register(). I thought that every static global variable got
initialized regardless of their usage afterwards. Is this not true?
Can I blame it on the compiler (I'm using vc++ 7.1 which is very good)
? When I go ahead and reference one function in the source file which
doesn't register the class, it now does register it.
I am trying this by linking the static library with my executable (a
game). Does static libraries have different global initialization
rules?
If you need any more information, please don't hestitate to ask.
Thanks a lot,
George Faraj