P
pauldepstein
I liked this article by Danny Kalev on the singleton design class:
http://gethelp.devx.com/techtips/cpp_pro/10min/10min0200.asp
However I was confused by this:
QUOTE BEGINS HERE
The class's implementation looks like this:
Singleton* Singleton:instance = 0;// initialize pointer
Singleton* Singleton::Instance ()
{
if (pinstance == 0) // is it the first call?
{
pinstance = new Singleton; // create sole instance
}
return pinstance; // address of sole instance
}
Singleton::Singleton()
{
//... perform necessary instance initializations
}
QUOTE ENDS HERE
My confusion stems from the fact that pinstance is a private static
member of Singleton.
So I would have thought that Singleton* Singleton:instance = 0;
violates private access.
What am I missing?
Thanks,
Paul Epstein
http://gethelp.devx.com/techtips/cpp_pro/10min/10min0200.asp
However I was confused by this:
QUOTE BEGINS HERE
The class's implementation looks like this:
Singleton* Singleton:instance = 0;// initialize pointer
Singleton* Singleton::Instance ()
{
if (pinstance == 0) // is it the first call?
{
pinstance = new Singleton; // create sole instance
}
return pinstance; // address of sole instance
}
Singleton::Singleton()
{
//... perform necessary instance initializations
}
QUOTE ENDS HERE
My confusion stems from the fact that pinstance is a private static
member of Singleton.
So I would have thought that Singleton* Singleton:instance = 0;
violates private access.
What am I missing?
Thanks,
Paul Epstein