On Wed, 28 Dec 2005 17:41:46 -0800, Steven Woody wrote:
> hi,
>
> my friend ask me the following question. even thogth i prefer the
> solution 3, but i owe an explanation.
>
>
> -------------------------------
>
> I create three versions for singletone pattern below, plz compare them
> with advantage and disadvantage:
>
<snip>
4.
MyApp.hpp
class MyApp
{
public:
static MyApp& getInstance()
{
static MyApp appInstance;
return appInstance;
}
private:
MyApp() {;}
};
Doesn't get constructed until you call it the first time (so you don't
have to worry about initialization order), and it will be destructed
automatically when the program exits.
- Jay
|