Commit 075bf877 authored by Ronan's avatar Ronan
Browse files

fix(Singleton): better code

parent e4415e9b
......@@ -31,31 +31,17 @@ public:
virtual ~Singleton () = default;
static T *getInstance () {
if (!mInstance) {
mInstance = new T();
static SingletonDeleter deleter;
}
return mInstance;
static T instance;
return &instance;
}
protected:
explicit Singleton (ObjectPrivate &p) : Object(p) {}
private:
struct SingletonDeleter {
~SingletonDeleter () {
delete mInstance;
}
};
static T *mInstance;
L_DISABLE_COPY(Singleton);
};
template<class T>
T *Singleton<T>::mInstance = nullptr;
LINPHONE_END_NAMESPACE
#endif // ifndef _SINGLETON_H_
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment