Re: strange crush when using template singleton class

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"andrew" <user@earth> wrote in message
news:%23UjQHJLaHHA.3996@xxxxxxxxxxxxxxxxxxxxxxx

Since I am using a template and since template only use inline code and
this could mean internal linkage for GetInstance( ) method.
Isn't it possible that what I get is multiple copies of that object ?

While template functions aren't guaranteed to be inlined, that does sound
like a plausible explanation - if Instance() is inlined, you'll definitely
not have a singleton any more. You can, of course, simply move the static T
out of Instance() and into class scope, and then you'll be guaranteed to
have a single instance per assembly (EXE/DLL).

Incidentally, the code you posted shouldn't compile - if it does, it's a bug
in VC 7.1 (I only tried VC8).

private:
operator=(const CSingleton&);

There's no return type for this function, so it's not a legal declaration.
The correct declaration would be

private:
CSingleton& operator=(const CSingleton&);

-cd


.



Relevant Pages