繁体   English   中英

test1.cpp:9:77: 错误:不匹配调用 '(const std::normal_distribution<double> ) (std::mt19937&)'</double>

[英]test1.cpp:9:77: error: no match for call to ‘(const std::normal_distribution<double>) (std::mt19937&)’

我有这段代码:

class Y {
    private:
        std::normal_distribution<double> N;
    public:
        Y() : N(0,1) {}
        double operator()(const double & x, std::mt19937 G) const { return x + N(G); }
};

我有这个错误:

错误:与“(const std::normal_distribution) (std::mt19937&)”的调用不匹配

对于该行:

    double operator()(const double & x, std::mt19937 G) const { return x + N(G); }

运算符std::normal_distribution<T>::operator()(Generator& g)是非常量成员 function,因此不能为常量 object 调用。只需从 function 定义中删除const

double operator()(const double & x, std::mt19937 &G) { return x + N(G); }

另请注意,您很可能希望通过引用传递生成器参数

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM