Files
Renderive/YSGraphic_Core/base/SingletonWidget.hpp
T
2026-06-16 13:33:27 +08:00

28 lines
798 B
C++

#pragma once
#include <QDebug>
namespace YSG {
template<typename T>
class SingletonWidget {
public:
static T *instance() {
if (!mInstance) {
qInfo() << "error SingletonWidget 未创建" << mInstance;
}
return mInstance;
}
SingletonWidget() {
if (mInstance) {
qInfo() << "error SingletonWidget 重复创建" << mInstance;
}
mInstance = static_cast<T *>(this);
}
virtual ~SingletonWidget() {}
SingletonWidget(T &&) = delete;
SingletonWidget(const T &) = delete;
void operator=(const T &) = delete;
protected:
static T *mInstance;
};
template<typename T> T *SingletonWidget<T>::mInstance = nullptr;
}