VRController編寫
寫了一個線程安全的單例來使用,打包安卓程序缺直接閃退。
改回傳統單例然後該問題結束。
未找到原因。
一句話概括單例的寫法:構造函數聲明爲private或者protected防止被外部函數實例化,內部保存一個private static的類指針保存唯一的實例,實例的動作由一個public的類方法代勞,該方法也返回單例類唯一的實例。
//.h
class singleton
{
private:
singleton(){}
static singleton* p;
~singleton();
public:
static singleton* GetInstance()
{
if(p == nullptr)
{
p = new singleton();
}
return p;
}
void Destory()
{
if (nullptr == p)
{
delete p;
p = nullptr;
}
}
}
//.cpp
singleton* singleton::p = nullptr;
//.h
class singleton
{
private:
singleton(){}
static singleton* p;
~singleton(){}
public:
static singleton* GetInstance()
{
return p;
}
void Destory()
{
if (nullptr == p)
{
delete p;
p = nullptr;
}
}
}
//.cpp
singleton* singleton::p = new singleton;