1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#if !defined(__SINGLETON_AUTO_PTR__)
#define __SINGLETON_AUTO_PTR__
 
#include <memory>
#include "uncopyable.h"
 
template <typename T>
class Singleton : public uncopyable {
public:
    static T* getInstance(){
        static const std::auto_ptr<T> __instance(new T);
        return __instance.get();
    }
protected:
    Singleton(){};
    virtual ~Singleton(){};
};
 
#endif
1
2
3
4
5
6
7
8
9
10
11
12
#ifndef UNCOPYABLE_H_
#define UNCOPYABLE_H_
 
class uncopyable{ // Idea from Effictive C++ by Scott Meyers
protected:
    uncopyable() {}
    ~uncopyable() {}
private:
    uncopyable(const uncopyable &);
    uncopyable & operator=(const uncopyable &);
};
#endif