How do I call ::std::make_shared on a class with only protected or private constructors?

I have this code that doesn’t work, but I think the intent is clear: testmakeshared.cpp #include <memory> class A { public: static ::std::shared_ptr<A> create() { return ::std::make_shared<A>(); } protected: A() {} A(const A &) = delete; const A &operator =(const A &) = delete; }; ::std::shared_ptr<A> foo() { return A::create(); } But I get this … Read more

Difference in make_shared and normal shared_ptr in C++

std::shared_ptr<Object> p1 = std::make_shared<Object>(“foo”); std::shared_ptr<Object> p2(new Object(“foo”)); Many google and stackoverflow posts are there on this, but I am not able to understand why make_shared is more efficient than directly using shared_ptr. Can someone explain me step by step sequence of objects created and operations done by both so that I will be able to … Read more