Is this a correct implementation of a generic Meyers Singleton in C++17? Any tips appreciated.
Singleton.h
#ifndef SINGLETON_H
#define SINGLETON_H
template<class T>
class Singleton
{
public:
static T& get()
{
static T obj;
return obj;
}
protected:
Singleton() = default;
virtual ~Singleton() = default;
Singleton(const Singleton&) = delete;
Singleton(Singleton&&) = delete;
Singleton& operator=(const Singleton&) = delete;
Singleton& operator=(Singleton&&) = delete;
};
#endif
MySingleton.h
#ifndef MYSINGLETON_H
#define MYSINGLETON_H
class MySingleton : public Singleton<MySingleton>
{
friend class Singleton<MySingleton>;
public:
// public members
private:
MySingleton() {};
~MySingleton() {};
};
#endif