【宅女求讲解一段程序】 virtual constructor
书上有一段程序。老师要求我们会运用。但是我怎么都看不懂= =求大神讲解.。分不是很多 = =帮个俺的话可以去回我别的帖子。我在继续发分。。每天都有新分嘛!
这貌似是关于虚基类指针还是神马的东西。。还有clone函数virtual copy constructor
#ifndef PAYOFFBRIDGE_H
#define PAYOFFBRIDGE_H
#include<PayOff3.h>
class PayOffBridge
{
public:
PayOffBridge(const PayOffBridge& original);
PayOffBridge(const PayOff& innerPayOff);
inline double operator()(double Spot) const;
~PayOffBridge();
PayOffBridge& operator=(const PayOffBridge& original);
private:
PayOff* ThePayOffPtr;
};
inline double PayOffBridge::operator()(double Spot) const
{
return ThePayOffPtr->operator ()(Spot);
}
#endif
PayOffBridge::PayOffBridge(const PayOffBridge& original)
{
ThePayOffPtr = original.ThePayOffPtr->clone();
}
PayOffBridge::PayOffBridge(const PayOff& innerPayOff)
{
ThePayOffPtr = innerPayOff.clone();
}
PayOffBridge::~PayOffBridge()
{
delete ThePayOffPtr;
}
PayOffBridge& PayOffBridge::operator=
(const PayOffBridge& original)
{
if (this != &original)
{
delete ThePayOffPtr;
ThePayOffPtr = original.ThePayOffPtr->clone();
}
return *this;
}