Boost logo

Boost Users :

From: Roland Schwarz (roland.schwarz_at_[hidden])
Date: 2004-12-27 06:36:10


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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net