#include #include #include #include #include #include boost::signal sig; class Foo: public boost::enable_shared_from_this, public boost::postconstructible { public: static boost::shared_ptr create() { return boost::deconstruct_ptr(new Foo()); } virtual void postconstruct() { typedef typeof(sig) sig_type; sig.connect( sig_type::slot_type(&Foo::some_func, this).track(shared_from_this())); } void some_func() { std::cout << __PRETTY_FUNCTION__ << std::endl; /*...*/ } private: Foo() {/*...*/} }; int main() { boost::shared_ptr f = Foo::create(); sig(); f.reset(); sig(); return 0; }