Re: Initialization methods in library..

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux