class PayOffBridge
{
public:
PayOffBridge();
PayOffBridge(const PayOffBridge& original);
PayOffBridge(const PayOff& innerPayOff);
inline double operator()(double Spot) const;
~PayOffBridge();
PayOffBridge& operator=(const PayOffBridge& original);
private:
PayOff* ThePayOffPtr;
};
and another class with a member which is an object of class PayOffBridge
:
class VanillaOption
{
public:
VanillaOption(const PayOffBridge& ThePayOff_, double Expiry);
double OptionPayOff(double Spot) const;
double GetExpiry() const;
private:
double Expiry;
PayOffBridge ThePayOff;
};
The PayOff* ThePayOffPtr
in PayOffBridge
is a pointer to the following pure virtual abstract class:
class PayOff
{
public:
PayOff(){};
virtual double operator()(double Spot) const=0;
virtual ~PayOff(){}
virtual PayOff* clone() const=0;
private:
};
The concrete class PayOffCall
is derived from PayOff
. In main()
I have
PayOffCall thePayOff(Strike);//double Strike
VanillaOption theOption(thePayOff, Expiry);//double Expiry
When I step through the code using F11 in Visual Studio, the line VanillaOption theOption(thePayOff, Expiry);
ends up calling PayOffBridge(const PayOff& innerPayOff);
. I cannot figure out from where this gets called. How does the constructor for VanillaOption
end up calling this?
My 2nd question is the constructor for VanillaOption
which gets called from main()
is
VanillaOption::VanillaOption(const PayOffBridge& ThePayOff_, double Expiry_): ThePayOff(ThePayOff_), Expiry(Expiry_)
{
}
What exactly does ThePayOff(ThePayOff_)
do? That is, which constructor of PayOffBridge
gets called, if at all, and what exactly does this syntax accomplish?