• (nodebb)
    // Frist.h
    
    class Frist
    {
       /// Blah blah C++ stuf blah blah
    }
    
    static Frist* g_frist = Frist();
    

    That's got to work surely? I'll only get one in my program?

  • Anonymous Coward (unregistered)

    Obviously, the way to create singletons is to use pthread_once.

  • (nodebb)

    :%s/design pattern/bad programming/g

  • (author) in reply to Bananafish

    Most (but not all) uses of the singleton pattern are bad programming. It is almost always better to manage the lifecycle of a single instance through more conventional methods- like just creating one instance of it.

  • (nodebb)

    where, or where,

    Whether typo or eggcorn, that's really poetic! The more conventional phrase would be "where oh where".

  • (nodebb) in reply to jeremypnet

    What that will do is create a separate Frist instance for each compilation unit (.cpp file), not visible from other compilation units. To create a true program-wide singleton, you need to declare it as extern in the .h file, and have exactly one .cpp file defining the instance.

  • Duke of New York (unregistered)
    Comment held for moderation.
  • Klimax (unregistered)
    Comment held for moderation.

Leave a comment on “A Single Lint Problem”

Log In or post as a guest

Replying to comment #:

« Return to Article