- Joined
- Feb 21, 2008
- Messages
- 1
- Reaction score
- 0
Hello,
Can somebody tell me why in all the classic implementations of a singleton you have to return a reference to an instance of the class. What is the problem with implementing it as such:
class Singleton
{
public:
static Singleton s;
private:
Singleton(){}
Singleton(const Singleton&);
Singleton &operator=(const Singleton&);
};
The constructor is private and the public instantiation of the object is static. It seems sloppy to allow public access to the object, but is there any other inherent problem?
Can somebody tell me why in all the classic implementations of a singleton you have to return a reference to an instance of the class. What is the problem with implementing it as such:
class Singleton
{
public:
static Singleton s;
private:
Singleton(){}
Singleton(const Singleton&);
Singleton &operator=(const Singleton&);
};
The constructor is private and the public instantiation of the object is static. It seems sloppy to allow public access to the object, but is there any other inherent problem?