Private constructor and make_shared

Viewed 8338

I have a singleton class with a private constructor. In the static factory method I do the following:

shared_ptr<MyClass> MyClass::GetInstance()
{
    static once_flag onceFlag;

    call_once(onceFlag, []() {
        if (_instance == nullptr)
            _instance.reset(new MyClass());
    });

    return _instance;
}

If I use

_instance = make_shared<MyClass>();

the code does not compile. My question is: why new can invoke a private constructor but make_shared not?

3 Answers
Related