Secure Singleton

Laethnes
2009-09-01
2013-04-08
  • Laethnes

    Laethnes - 2009-09-01

    I'm not sure, if I something misunderstand, but I'm woriing about security making only one instace of singleton. (I have readed Modern programing in c++)

    I can make a any number of them:

    #include "Singleton.h"

    class ExperimentClass
    {
        private:
            ExperimentClass();
            ~ExperimentClass();
            ExperimentClass(ExperimentClass&);
            ExperimentClass& operator=(ExperimentClass&);
           
            friend class Loki::CreateUsingNew<ExperimentClass>;
           
        public:
           
            // ...
           
    };

    typedef Loki::SingletonHolder<ExperimentClass, Loki::CreateUsingNew> ExperimentClassSingleton;

    void Experiment()
    {
        ExperimentClass &instance1 = ExperimentClassSingleton::Instance();
        ExperimentClass *instance2 = Loki::CreateUsingNew<ExperimentClass>::Create();
    }

     
    • Laethnes

      Laethnes - 2009-09-01

      I'm sorry, I send it to "OpenDiscussion", not "Developers". Can I or Admin move it to the right place?

       
  • chen shu

    chen shu - 2011-05-06

    No way to handle your question if you add some friend classes or functions into your own classes.
    But you told me there was no perfect solution,Loki just helped close to our goals.

     
  • Laethnes

    Laethnes - 2011-08-15

    - If I will not add friend, Loki's singleton holder will not be able to create any instance, if I understand it correctly, so I have to.
    - I see. Ok ;).

    Thanks for answer and sorry for late reply, it looks like I failed to set up monitoring this thread correctly.

     

Log in to post a comment.