
27 Dec
2004
27 Dec
'04
11:36 a.m.
I have found that it is bossible to create an in place functor like object by combining function, bind and shared_ptr. However altough it seems to work I am not sure whether this is safe usage. I would be glad if someone more knowledgeable had a look on it: class bar { void foo() { } }; boost::function<void ()> pfoo; int main(int argc, char* argv[]) { pfoo = boost::bind(&bar::foo, boost::shared_ptr<bar>(new bar)); pfoo(); // ... pfoo = 0; // this operation causes the ~bar dtor to be called return 0; } Thank you, Roland