【问题标题】:Creating a discrete distribution in Visual Studio在 Visual Studio 中创建离散分布
【发布时间】:2015-07-01 16:53:44
【问题描述】:

我想在 Visual Studio 中使用 121 个整数创建自己的离散分布。这是我正在尝试的代码:

std::vector< int> weights(121);
for (int i = 0; i < 121; i++)
{
    weights[i] = (teamData[i]).S(); // some numbers from my program data 
}
std::discrete_distribution<> dist(weights.begin(), weights.end());

我收到智能错误:

1   IntelliSense: no instance of constructor "std::discrete_distribution<_Ty>::discrete_distribution [with _Ty=int]" matches the argument list
        argument types are: (std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>, std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>)    

当我编译时,我得到:

错误 1 ​​错误 C2661:“std::discrete_distribution::discrete_distribution”:没有重载函数需要 2 个参数
有谁知道解决这个问题?

【问题讨论】:

  • 这是一个智能感知错误,它真的可以编译吗?智能感知不只是 VS 中的自动完成功能吗?
  • 我刚刚添加了编译时遇到的错误
  • 当你声明 dist. Discrete_distribution 的默认类型是 但您正在尝试使用迭代器将其初始化为 int 向量。我认为这只有在你传递一组整数而不是两个不代表整数的参数时才有效。
  • @RyanP 谢谢,但我不确定如何将一组整数传递给分布。
  • 如果你谷歌我的错误信息,有一个链接,它只是说要更新 VS 2013,我这样做了,但仍然得到同样的错误。

标签: c++ distribution


【解决方案1】:

http://en.cppreference.com/w/cpp/numeric/random/discrete_distribution/discrete_distribution

您正在使用迭代器对其进行初始化,因此您需要使用此构造函数

template< class InputIt >
discrete_distribution( InputIt first, InputIt last );

所以我猜应该是std::discrete_distribution&lt;int&amp;&gt; dist(weights.begin(), weights.end());

但我之前没有使用过discrete_distribution。

【讨论】:

  • 当我尝试使用它时,它说“dist”是未定义的!
  • 谢谢。我错过了课程模板!你解决了我的问题!
  • 太棒了!确保将此标记为您接受的答案,以维护我的声誉:)
  • 您好,抱歉,我从模板 收到“未解决的外部错误”。我应该将这段代码粘贴到哪里?
  • 如果这是一个新问题,我会提出一个新问题。如果它与此直接相关,我会更新您的原始问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-10-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-18
  • 1970-01-01
  • 2020-10-24
相关资源
最近更新 更多