C++, Can't instantiate abstract class error -
the compiler gives error cannot instantiate abstract class due following members:
how sort this?
'double payoff::operator ()(const double &) const' : abstract
this abstract class
class payoff { public: virtual ~payoff() {} virtual double operator()(const double& spot) const = 0; virtual std::shared_ptr<payoff> clone() const = 0; };
derived class
class asiangeometric: public payoff{ private: double strike; public: asiangeometric(const double& strike); virtual ~asiangeometric(){}; virtual double asianpay()(const std::vector<double>& spot_prices) const; virtual std::shared_ptr<payoff> clone()const; }; asiangeometric::asiangeometric(const double& strike){ this-> strike = strike; } double asiangeometric::asianpay(const std::vector<double>& spot_prices) const{ unsigned num_times = spot_prices.size(); double log_sum = 0.0; (unsigned int i=0; i<spot_prices.size(); i++){ log_sum += log(spot_prices[i]); } double geom_mean = exp(log_sum/static_cast<double>(num_times)); if (geom_mean > strike) return geom_mean - strike; else return 0; } std::shared_ptr<payoff> asiangeometric::clone()const{ return std::shared_ptr<payoff>(new asiangeometric(*this)); }
you aware that:
virtual double operator()(const std::vector<double>& spot_prices) const;
does not override:
virtual double operator()(const double& spot) const = 0;
right?
Comments
Post a Comment