- 749 名前:デフォルトの名無しさん mailto:sage [2009/08/21(金) 15:32:03 ]
- >>747こうすると、shared_ptrに捕まえられたファンクタがfに代入される。ただ、F()でF()のファンクタを作る意味がないけど。さらにfで保持すると参照カウンタが0にならなくなる。
ファンクタを作りたいなら、mainで bind(&Derived::F,d)とすればすむ筈。 #include <boost/bind.hpp> #include <boost/shared_ptr.hpp> #include <boost/enable_shared_from_this.hpp> #include <boost/function.hpp> typedef boost::function< void () > func_t; class Base { public: void N(){}; }; class Derived :public Base, public boost::enable_shared_from_this< Derived > { public: void F() { f = boost::bind( &Derived::F, this->shared_from_this() ); }; func_t f; }; int main() { boost::shared_ptr< Derived > d( new Derived ); d->F(); func_t x=boost::bind(&Derived::F,d); return 0; }
|

|