C ++用户定义的抽象类构造函数

时间:2015-08-14 09:40:23

标签: c++ design-patterns

在下面的代码中(来自Mark Joshi的C ++ Design Design Patterns and Derivatives Pricing),任何人都可以解释为什么我们必须在抽象类PayOff中声明默认构造函数PayOff(){}? p>

提前谢谢你 此致

#ifndef PAYOFF3_H
#define PAYOFF3_H

class PayOff
{
public:

    PayOff(){};

    virtual double operator()(double Spot) const=0;
    virtual ~PayOff(){}
    virtual PayOff* clone() const=0;

private:

};

class PayOffCall : public PayOff
{
public:

    PayOffCall(double Strike_);

    virtual double operator()(double Spot) const;
    virtual ~PayOffCall(){}
    virtual PayOff* clone() const;

private:

    double Strike;

};


class PayOffPut : public PayOff
{
public:

    PayOffPut(double Strike_);

    virtual double operator()(double Spot) const;
    virtual ~PayOffPut(){}
    virtual PayOff* clone() const;

private:

    double Strike;

};

#endif

0 个答案:

没有答案