B
baumann@pan
hi all,
according the private / protected access control,
- private; that is, its name can be used only by members and friends
of the class in which it is
declared.
- protected; that is, its name can be used only by members and
friends of the class in which it is
declared, and by members and friends of classes derived from this class
(see 11.5).
how can the codes below work correctly since the static function
Instance() should not have the accesss to private constructor
Singleton(); moreover, the statement static Singleton theInstance would
call the private constructor Singleton() to create the instance of the
class Singleton, but the static variable is not the members or friends
of the class Singleton, so the static variable could not access the
private constructor of the class Singleton.
anyone could point out why I am wrong? thanks in advance.
class Singleton
{
public:
static Singleton& Instance ()
{
static Singleton theInstance;
return theInstance;
}
private:
Singleton () {}
};
baumann@pan
according the private / protected access control,
- private; that is, its name can be used only by members and friends
of the class in which it is
declared.
- protected; that is, its name can be used only by members and
friends of the class in which it is
declared, and by members and friends of classes derived from this class
(see 11.5).
how can the codes below work correctly since the static function
Instance() should not have the accesss to private constructor
Singleton(); moreover, the statement static Singleton theInstance would
call the private constructor Singleton() to create the instance of the
class Singleton, but the static variable is not the members or friends
of the class Singleton, so the static variable could not access the
private constructor of the class Singleton.
anyone could point out why I am wrong? thanks in advance.
class Singleton
{
public:
static Singleton& Instance ()
{
static Singleton theInstance;
return theInstance;
}
private:
Singleton () {}
};
baumann@pan