Re: strange crush when using template singleton class
- From: "Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@xxxxxxxxxxxxxxx>
- Date: Sat, 17 Mar 2007 10:25:13 -0700
"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
.
- Follow-Ups:
- Re: strange crush when using template singleton class
- From: Dr Pizza
- Re: strange crush when using template singleton class
- References:
- strange crush when using template singleton class
- From: andrew
- Re: strange crush when using template singleton class
- From: Carl Daniel [VC++ MVP]
- Re: strange crush when using template singleton class
- From: andrew
- strange crush when using template singleton class
- Prev by Date: Re: strange crush when using template singleton class
- Next by Date: Re: strange crush when using template singleton class
- Previous by thread: Re: strange crush when using template singleton class
- Next by thread: Re: strange crush when using template singleton class
- Index(es):
Relevant Pages
|