Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2007-10-16 14:42:39


on Wed Sep 26 2007, "Preston A. Elder" <prez-AT-neuromancy.net> wrote:

> (repost, I accidentally posted this to boost::build list ... ugh).
>
> I have written code to solve this problem:
>
> I have class foo, like so:
>
> class foo
> {
> boost::function<void (foo *)> func_ptr;
>
> void call()
> {
> func_ptr(this);
> }
> };
>
> I want func_ptr to be either a free-standing function (or class static), OR
> a class member function of a derived class, so:
>
> void bar(foo *f) { ... }
>
> OR:
>
> class baz : public foo
> {
> public:
> baz()
> {
> func_ptr = &baz::doit;
> }
>
> void doit() { }
> };
>
> The obvious problem with the latter is that it needs to be downcast
> implicitly, and some kind of exception thrown if the wrong type is passed.

I think this is what Boost.Bind is for.

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk