private:
inline static Singleton* instance = nullptr;
Singleton() {}
public:
static Singleton* getInstance()
{
if(!instance)
instance = new Singleton();
return instance;
}
};
i have a question about !, will compiler optimize it to compare with 0?
No delete for 'operator='?
Put instance inside of method and make instance static.
Wow, you made an even worse one lol
class Singleton { Singleton() {} Singleton(Singleton&) = delete; Singleton(Singleton&&) = delete; void operator=(Singleton&) = delete; void operator=(Singleton&&) = delete; public: static Singleton& getInstance() { static Singleton instance; return instance; } };
Обсуждают сегодня