没有构造函数的实例匹配参数列表

时间:2016-11-21 14:20:57

标签: c++ c++11 inheritance

我知道之前已经问过这个问题,我尝试过发布的解决方案,但由于某种原因,我仍然无法解决我所面临的问题。

我正在尝试创建派生类的对象。但是,我收到一条错误消息:

Error: no instance of constructor "CALibrary::YieldCurve::YieldCurve"
matches te argument list argument types are: (std::string,
std::vector<std::pair<double,double>,double>)

父类是:

namespace CALibrary {
  class YieldCurveIF {
  public:
    virtual double getDiscountFactor(double fromDate, double toDate) = 0;
      int getSize() {
        return _curve.size();
      }
      std::vector<std::pair<double, double>> getCurve() {
        return _curve;
      }

      void setParameters(std::string curveName,
                         std::vector<std::pair<double, double>>& curve)
      {
        _curveName = curveName;
        _curve = curve;
      }
  protected:
    std::string                            _curveName;
    std::vector<std::pair<double, double>> _curve;
  };
}

派生类是:

namespace CALibrary {
  class YieldCurve : public CALibrary::YieldCurveIF
  {
  public:
    YieldCurve(std::string curveName,
               std::vector<std::pair<double, double>>& curve)
    {           
      setParameters(curveName, curve);
    }
    double getDiscountFactor(double fromDate, double toDate);
    private:
  };
}

以下是我尝试创建YieldCurve对象的代码:

int nPayments = 4;
std::string curveName = "EURCurve"; 
std::vector<std::pair<double, double>, double> yCurve(nPayments);
CALibrary::YieldCurve   _yieldCurve(curveName, yCurve);

1 个答案:

答案 0 :(得分:0)

yCurve有一个无意义的类型

std::vector<std::pair<double, double>, double>

删除最后的,double

此外,如果代码在两个地方占用std::vector<std::pair<double, double>>&,则代码需std::vector<std::pair<double, double>> const&