Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- //Credits: Scott Meyers
- class Singleton {
- public:
- static Singleton& getIstanza() {
- static Singleton istanza_;
- return istanza_;
- }
- //TEST COPY CONSTRUCTOR
- // void f1()
- // {
- // f2(getIstanza());
- // }
- //
- // void f2(Singleton copia_del_singleton)
- // {
- // //in questo momento esisterebbero DUE istanze di un singleton
- // }
- // void f(Singleton copia_del_singleton)
- // {
- // //in questo momento esisterebbero DUE istanze di un singleton
- // }
- //TEST COPY ASSIGNMENT
- // void f()
- // {
- // Singleton copia = getIstanza();
- // }
- private:
- Singleton() { cout << "Invocato costruttore" << endl; }
- //Singleton(const Singleton&) = delete;
- Singleton& operator=(const Singleton&) = delete;
- ~Singleton() { cout << "Invocato distruttore" << endl; }
- };
- int main()
- {
- Singleton& il_singleton = Singleton::getIstanza();
- Singleton& un_altro_singleton = Singleton::getIstanza();
- //il_singleton.f1();
- //f(il_singleton); //no distruttore privato!
- //il_singleton.f(il_singleton);
- //VARIANTE PER MASSIME PERFORMANCE
- //cercare: c++ singleton pimpl implementation
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement