I have this code that doesn\'t work, but I think the intent is clear:
testmakeshared.cpp
#include
class A {
public:
stat
#include
#include
class A : public std::enable_shared_from_this
{
private:
A(){}
explicit A(int a):m_a(a){}
public:
template
static std::shared_ptr create(Args &&... args)
{
class make_shared_enabler : public A
{
public:
make_shared_enabler(Args &&... args):A(std::forward(args)...){}
};
return std::make_shared(std::forward(args)...);
}
int val() const
{
return m_a;
}
private:
int m_a=0;
};
int main(int, char **)
{
std::shared_ptr a0=A::create();
std::shared_ptr a1=A::create(10);
std::cout << a0->val() << " " << a1->val() << std::endl;
return 0;
}