I know that Scott Meyers Singleton is thread safe for C++11 and above. Does the following code is thread safe (for C++11 and above) ?
class T
{
static T* obj;
public:
T& GetInstance()
{
if (!obj)
{
obj = new T();
}
return *obj;
}
};
T* T::obj=nullptr;
Aucun commentaire:
Enregistrer un commentaire