Return reference to instance of singleton

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top