I have a
class BC_TOYFD
{
public:
BC_TOYFD( BS_TOYFD * pBS, BC2 dBC2 );
virtual ~BC_TOYFD( void ) ;
BS_TOYFD * _pBS ;
BC2 _dBC2 ;
double _PDA ; // store price down approximation
double _PUA ; // store price up approximation
virtual void COMPUTEBVDOWNFOR( PAYOFF_TOYFD * pPAYOFF, double * attime ) = 0 ;
virtual void COMPUTEBVUPFOR( PAYOFF_TOYFD * pPAYOFF, double * attime ) = 0 ;
};
from which derives a
class DIRICHLET_TOYFD : public BC_TOYFD
{
public:
DIRICHLET_TOYFD( BS_TOYFD * pBS, BC2 dBC2 ) ;
~DIRICHLET_TOYFD( void ) ;
void COMPUTEBVDOWNFOR( PAYOFF_TOYFD * pPAYOFF, double * attime ) ;
void COMPUTEBVUPFOR( PAYOFF_TOYFD * pPAYOFF, double * attime ) ;
};
and I would like the methods
void DIRICHLET_TOYFD::COMPUTEBVDOWNFOR( PAYOFF_TOYFD * pPAYOFF, double * attime )
and
void DIRICHLET_TOYFD::COMPUTEBVUPFOR( PAYOFF_TOYFD * pPAYOFF, double * attime )
to do things accordingly to the runtime type of pPAYOFF, but without resorting to a
dynamic_cast<>
Typically,
void DIRICHLET_TOYFD::COMPUTEBVDOWNFOR( PAYOFF_TOYFD * pPAYOFF, double * attime )
would do something like
_PUA = something if the runtime type of pPAYOFF (which is an abstract class) is for instance CALL_TOYFD
and
_PUA = something else if the runtime type of pPAYOFF (which is an abstract class) is for instance PUT_TOYFD
where CALL_TOYFD and PUT_TOYFD are public derived from PAYOFF_TOYFD. And after, I would like to be able to write something like
double approx = bc->COMPUTEBVDOWNFOR( pPAYOFF, attime ) ;
where bc is an instance of BC_TOYFD, and where pPAYOFF is a pointer to PAYOFF_TOYFD, such that the right types for bc and pPAYOFF are resolved at runtime.
I have been told to use "double dispatch" or "reverse double dispatch" pattern for, without any other hint/precision. I have tried to implement it in this framework, without really knowing how to do it exactly. By the way, I will have "other" classes like DIRICHLET_TOYFD deriving from BC_TOYFD, for which I will have to save the same problem that the one I am trying to solve, so that I guess that the double dispatch put in practice in my case will have to take this constraint into account.
Any help would be appreciated !
Thanks a lot !