Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

static class member initialization

Status
Not open for further replies.

lexip

Programmer
Dec 17, 2004
2
0
0
CH
hello there,
I have a problem with static class memeber initialization.
I do the following:

std::string ClassA::sDummy
= ClassFactory<string,Module>
::RegisterCreatorFunction(std::string( "ClassA" ), ClassA::CreatorFunction );

this registers the creator function of the ClassA class to a map with "ClassA" as key. I use this for dynamic class instantiation. This means, I can create an instance of ClassA by just knowing the "ClassA" string (loading class according to a config file).

Well, this all worked fine as long as I used the GNU C compiler gcc/g++. I had to switch to the borland compiler bcc32 and since then it does not work any more. The RegisterCreatorFunction is never called!! Why are static class members not initialized at programm startup??

anybody got an idea? thanks a lot..

harald
 
You can't initialize values in a class definition. The variables shall be initialized in the constructor.

Totte
Keep making it perfect and it will end up broken.
 
I think you got me wrong, I'm not initializing variables in the class def. I have a static class member, and they need to be initialized!!
But anyway, I think I found a solution for the problem, by not compiling to a .lib file, but linking all obj's together directly solves the problem, and the static memeber is perfectly initialized..
thanks anyway
 
Nevertheless the answer would be the same.

Though you does not declare as variable but as constant.

But i shall be done the same way, in the constructor or whereevere applicable.

Totte
Keep making it perfect and it will end up broken.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top