Skip to content

Instantly share code, notes, and snippets.

@0xa
Created March 16, 2013 15:16
Show Gist options
  • Save 0xa/5176833 to your computer and use it in GitHub Desktop.
Save 0xa/5176833 to your computer and use it in GitHub Desktop.
#ifndef COMMON_SINGLETON_H
#define COMMON_SINGLETON_H
#include <memory>
template<typename T>
class Singleton {
public:
static inline std::shared_ptr<T> GetInstancePtr() {
static std::shared_ptr<T> instance = new T();
return instance;
}
static inline T& GetInstance() {
return *GetInstancePtr();
}
private:
Singleton();
Singleton(const Singleton<T> &);
Singleton& operator=(const Singleton<T> &);
};
#endif // COMMON_SINGLETON_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment