Boost logo

Boost Users :

Subject: Re: [Boost-users] Using boost function with virtual methods
From: Igor R (boost.lists_at_[hidden])
Date: 2011-07-02 13:21:13


> typedef boost::function<void (RegressionTestScenario*, const std::string &)> actionFuntion;
> typedef boost::shared_ptr<actionFuntion> actionFuntionPtr;
<...>
> class CurveGenRegressionTestScenario : public RegressionTestScenario
> {
> public:
>         void changeBaseDate(const std::string &argument);
<...>
> and I am trying to use the following:
>
> actionFuntion funPtr;
> funPtr = &CurveGenRegressionTestScenario::changeBaseDate;
>
> but it fails. I have no idea why. Could someone give me a hint?

boost::function<void (RegressionTestScenario*, const std::string &)>
-- is a callable with 2 arguments.
&CurveGenRegressionTestScenario::changeBaseDate -- is a ptr to a
member function.
These 2 types are incompatible.
You probably should look at Boost.Bind to accomplish your task:
http://www.boost.org/doc/libs/1_46_1/libs/bind/bind.html#with_member_pointers


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