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:25:14


> 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;


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