【问题标题】:no known conversion for argument from ‘std::exponential_distribution<double> (*)(double)’ to ‘std::exponential_distribution<double>*' [closed]从“std::exponential_distribution<double> (*)(double)”到“std::exponential_distribution<double>*”的参数没有已知的转换[关闭]
【发布时间】:2016-01-25 20:23:57
【问题描述】:

我不太明白g++ 向我抛出的这个错误。

std::exponential_distribution&lt;double&gt; (*)(double)std::exponential_distribution&lt;double&gt;* 有什么区别?

第二个显然是指向带有模板参数&lt;double&gt;std::exponential_distribution 的指针,但第一个是什么?

这是导致问题的代码:

首先是函数原型

simulation(std::mt19937_64 *mt19937_64_pointer,
           std::uniform_real_distribution<double> *uniform_real_dis_p,
           std::exponential_distribution<double> *exp_dis_p)
{
    ...
}

以及调用这个函数的代码:

std::mt19937_64 *gen_p = nullptr; // <-- this used to be: *&gen_p - hence the problem
    // Actually it isn't equal to nullptr - this is set elsewhere in the code

std::uniform_real_distribution<double> uniform_real_dis(0.0, 1.0);
std::exponential_distribution<double> exp_dis(1.0);

simulation s(gen_p, &uniform_real_dis, &exp_dis);

这是一个奇怪的错误 - 如果我完全理解它的含义,我相信我可以修复它。均匀分布有效而指数无效对我来说似乎很奇怪?

【问题讨论】:

  • 不应该是std::mt19937_64 *gen_p吗? this compiles
  • 奇怪的是为什么它可以编译而我的却没有。
  • 我删除了&amp;,您确定要同时使用*&amp;吗?
  • 哦,是的 - 大概就是这样
  • 是的,它正在工作。

标签: c++ c++11 random standard-library c++-standard-library


【解决方案1】:

你已经从 cmets 得到了答案,但为了记录,std::exponential_distribution&lt;double&gt; (*)(double) 是一个函数指针类型:一个函数接受一个 double 并返回一个 std::exponential_distribution&lt;double&gt;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-06
    • 1970-01-01
    • 1970-01-01
    • 2018-09-23
    • 1970-01-01
    • 2018-09-14
    • 2016-01-24
    • 1970-01-01
    相关资源
    最近更新 更多