
On Fri, Jul 1, 2011 at 1:06 PM, <przemyslaw.sliwa@uk.bnpparibas.com> wrote:
I have a simple inheritance:
class RegressionTestScenario;
typedef boost::function<void (RegressionTestScenario*, const std::string &)> actionFuntion;
class RegressionTestScenario { public: virtual ~RegressionTestScenario() {} };
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?
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.