This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Initialization methods in library..
- From: Eljay Love-Jensen <eljay at adobe dot com>
- To: Ajay Bansal <abansal at netegrity dot com>, gcc-help at gcc dot gnu dot org
- Date: Tue, 26 Aug 2003 07:42:50 -0500
- Subject: Re: Initialization methods in library..
- References: <20030825012837.QLIG3027.tomts9-srv.bellnexxia.net@romulus>
Hi Ajay,
What you are running into is an "order of construction" problem.
The general strategy to fix the problem is to make an accessor routine that returns the static variable.
Example:
class g_Master
{
public:
static CSmSimpleObj& getCSmSimpleObj();
}
CSmSimpleObj& g_Master::getCSmSimpleObj {
static CSmSimpleObj CacheCount;
static bool doInit = true;
if(doInit) {
CacheCount->Setvalue(1);
doInit = false;
}
return CacheCount;
}
If you REALLY want to have the _initfunc in the other library do the Setvalue(1), you'll need something like this:
CSmSimpleObj& g_Master::getCSmSimpleObj {
static CSmSimpleObj CacheCount;
static bool doInit = true;
if(doInit) {
_initfunc();
doInit = false;
}
return CacheCount;
}
HTH,
--Eljay