Boost logo

Boost Users :

Subject: Re: [Boost-users] Using boost function with virtual methods
From: Richard Damon (Richard_at_[hidden])
Date: 2011-07-02 13:58:53


On 7/2/11 1:25 PM, Igor R wrote:
>> The inheritance is going the wrong way. An actionFuntion instance
>> might be called with any RegressionTestScenario*. But you can't call a
>> CurveGenRegressionTestScenario method with any old
>> RegressionTestScenario* -- only a RegressionTestScenario* that is also
>> a CurveGenRegressionTestScenario* would be valid. The compiler isn't
>> going to synthesize logic for you to
>> dynamic_cast<CurveGenRegressionTestScenario&>(*your_first_param)
>> (which throws unless your_first_param is in fact a
>> CurveGenRegressionTestScenario*). If you want such logic, you'll have
>> to code an adapter and store that.
> It has nothing to do with inheritance. The following code won't compile as well:
>
> struct A
> {
> void f(int i);
> };
>
> boost::function<void(A *, int)> func = &A::f;
>
Note that func = $A::f does not have the same signature a &g where g is
defined as void g(A*, int);
It may act in an analogous manner, but the language does not make them
the same. I have seen some systems were the calling convention even put
the A* in a different register for the two calls.

-- 
Richard Damon

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