错误 - 多个运算符==匹配这些操作数

时间:2015-04-12 21:12:30

标签: c++ thread-safety singleton

我正在尝试制作一个“线程安全”的单身人士,但我收到了这个愚蠢的错误:

班级标题:

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;
}

谢谢

0 个答案:

没有答案