struct A: std::enable_shared_from_this<A>
{
private:
A(){};
public:
static shared_ptr<A> get_instance()
{
return shared_ptr<A>(new A);
}
Delegate *get_delegate()
{
retuern new Delegate(shared_from_this(), func);
}
};
main()
{
shared_ptr<A> a = A::get_instance();
Delegate * d = a->get_delegate();
a.reset();
d();
}
A *a = new A();
Delegate * d = a->get_delegate();