All,
I am using C++14 and am making a more-or-less standard Singleton. I am using the latest Visual Studio 2017. This code works:
#include <memory>
class A
{
public:
static A& getInstance()
{
if (instance == nullptr)
instance = std::unique_ptr<A>(new A());
return *instance;
}
private:
A() {}
static std::unique_ptr<A> instance;
};
std::unique_ptr<A> A::instance = nullptr;
However, when I change the creation of the singleton instance to this:
instance = std::make_unique<A>();
I get a compilation error that I am trying to access a private member:
Error C2248 'A::A': cannot access private member declared in class 'A'
c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\memory 2510
This feels like a bug to me, as the two forms should be identical in function? Thoughts?