|
Boost Users : |
Subject: Re: [Boost-users] Using boost function with virtual methods
From: Nat Linden (nat_at_[hidden])
Date: 2011-07-02 14:13:10
On Sat, Jul 2, 2011 at 1:21 PM, Igor R <boost.lists_at_[hidden]> wrote:
>> 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
I was going to suggest boost::bind(), but when I put the trimmed-down
code above into a source file, changed it to a boost::bind()
expression and tried to compile it with g++, it complained about the
type incompatibility. So there are two different problems, one of
which is inheritance.
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