Return reference to instance of singleton

Discussion in 'C Programming' started by airportman, Feb 21, 2008.

  1. airportman

    airportman

    Joined:
    Feb 21, 2008
    Messages:
    1
    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?
    airportman, Feb 21, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Proton Projects - Moin

    Singleton - Whether Cloneable overrides Singleton

    Proton Projects - Moin, Mar 26, 2007, in forum: Java
    Replies:
    4
    Views:
    3,233
    Proton Projects - Moin
    Mar 27, 2007
  2. Chris Forone
    Replies:
    3
    Views:
    298
    Frank Birbacher
    Aug 16, 2007
  3. Wilhelm
    Replies:
    1
    Views:
    162
    dblack@wobblini.net
    Oct 11, 2006
  4. Trans
    Replies:
    12
    Views:
    273
    Robert Klemme
    Sep 14, 2007
  5. Paul McMahon
    Replies:
    3
    Views:
    203
    David A. Black
    Jun 9, 2008
Loading...

Share This Page