I have this code:
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); }
};
And I have this error:
error: no match for call to '(const std::normal_distribution) (std::mt19937&)'
for the line:
double operator()(const double & x, std::mt19937 G) const { return x + N(G); }
Operator std::normal_distribution<T>::operator()(Generator& g)
is a non-const member function and thus cannot be called for a constant object. Just remove const
from your function definition:
double operator()(const double & x, std::mt19937 &G) { return x + N(G); }
Also note that you most likely want to pass generator argument by reference
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.