#pragma once
template <typename T>
class Singleton
{
public:
template<typename... Args>
static T* Instance(Args&&... args)
{
static TrashClean m_tc;
static std::once_flag oc;
std::call_once(oc, [&] { m_pInstance = new T(std::forward<Args>(args)...); });
return m_pInstance;
}
static void DestroyInstance()
{
delete m_pInstance;
m_pInstance = nullptr;
}
private:
Singleton(void);
~Singleton(void);
Singleton(const Singleton&);
Singleton& operator=(const Singleton&);
private:
class TrashClean {
public:
TrashClean()
{
}
~TrashClean()
{
DestroyInstance();
}
};
private:
static T* m_pInstance;
};
template<class T> T* Singleton<T>::m_pInstance = nullptr;
singleton-TrashClean
最新推荐文章于 2024-07-25 13:59:31 发布