我正在尝试制作一个“线程安全”的单身人士,但我收到了这个愚蠢的错误:
班级标题:
class Engine
{
public:
static Engine* Instance(void);
private:
Engine() {}
static std::atomic<Engine*> pinstance;
static std::mutex m_;
班级来源:
std::atomic<Engine*> Engine::pinstace { nullptr };
std::mutex Engine::_m;
Engine* Engine::Instance()
{
if (pinstance == nullptr) {
// ^^ I get error here
std::lock_guard<std::mutex> lock(m_);
if (pinstance == nullptr) {
// ^^ I get error also here
pinstance = new Engine();
}
}
return pinstance;
}
谢谢