Re: C++ singleton pattern question
From: Noah Roberts (nroberts_at_stmartin.edu)
Date: 02/22/05
- Next message: Ron Natalie: "Re: try-catch name"
- Previous message: Donovan Rebbechi: "Re: How to redefine operator delete/delete[] via macro?"
- In reply to: ferdinand.stefanus_at_gmail.com: "C++ singleton pattern question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 22 Feb 2005 09:54:41 -0800
ferdinand.stefanus@gmail.com wrote:
> Hi
>
> Could someone tell me what's the difference between these two
singleton
> implementations:
You don't control initialization in the first case. In the second case
you do.
I usually do something like this:
class Singleton
{
Singleton *instance;
Singleton() {}
public:
void function1() { blah; }
static void function1 { if (instance == NULL) instance = new
Singleton();
instance->function1(); }
};
in Singleton.cpp:
Singleton *Singleton::instance = NULL;
I don't know off hand if C++ allows static and non-static functions to
have same signature...you may have naming issues w/ regard to above.
It is the basic structure that is important. You will probably want a
const accessor also.
- Next message: Ron Natalie: "Re: try-catch name"
- Previous message: Donovan Rebbechi: "Re: How to redefine operator delete/delete[] via macro?"
- In reply to: ferdinand.stefanus_at_gmail.com: "C++ singleton pattern question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|