I want to enforce shared_ptr
for a few classes. I'm using a static
factory function to encapsulating private constructors:
#include <memory>
class MyClass
{
public:
static std::shared_ptr<MyClass> create() {
auto a = std::shared_ptr<MyClass>(new MyClass());
return a;
}
private:
MyClass();
~MyClass();
}
}
This template fails with C2440
, (function-style cast) in VS2017
, but works fine in VS2015
and I have no idea why. A make_shared-version works fine in both but requires public constructors.
Any idea which option I'm missing?