On 15 Jun 2005 03:44:19 -0700, "LinuxGuy" <>
wrote:
>Hi,
>
>I have come across singleton class with some member variables are
>declared as static with public scope.
> As singleton class always return only one instance. ie.
>single copy of object is maintained all the time. can someone tell me
>the reason behind declaring those variables as static one.
Well, the function used to return the singleton instance (usually
called "getInstance()" or something similar, and usually returning a
pointer to the singleton instance) MUST be static -- can you figure
out why? For similar reasons, there is often a static "unload()" or
"destroy()" function.
Otherwise, I would assume that other static functions are there for
the same reason we have static functions in any non-singleton class.
One of the more important ones might be that you cannot assign the
address of a non-static member function to a regular function pointer.
--
Bob Hairgrove