gpt4 book ai didi

c++ - 错误 C2338: !boost::is_integral::value with boost

转载 作者:行者123 更新时间:2023-11-30 01:56:42 26 4
gpt4 key购买 nike

我正在尝试在 oder 中使用 boost 来计算阶乘。我不知道为什么,但 VS2013 显示编译错误。

有人有什么想法吗?

int nLgCombi = 12;
std::vector<std::string> NbrToPlay;
...
int ne = NbrToPlay.size();
int calcnc = boost::math::factorial<int>(ne + 1) / boost::math::factorial<int>(nLgCombi);

错误信息:

Erreur 1 error C2338: !boost::is_integral::value d:\users\XXXXXX\downloads\boost_1_55_0b1\boost_1_55_0b1\boost\math\special_functions\factorials.hpp 32 1 APPS

编辑:

代码将 int 替换为 double:

double dcalcnc = boost::math::factorial<double>(ne +1) / boost::math::factorial<double>(nLgCombi);

错误信息:

Erreur 1 error C2039: 'assert_not_arg' : n'est pas membre de 'boost::mpl' d:\users\XXXXX\downloads\boost_1_55_0b1\boost_1_55_0b1\boost\mpl\aux_\preprocessed\plain\arg.hpp 45 1

Erreur 2 error C3861: 'assert_not_arg' : identificateur introuvable d:\users\XXXXX\downloads\boost_1_55_0b1\boost_1_55_0b1\boost\mpl\aux_\preprocessed\plain\arg.hpp 45 1

非常感谢,

最好的问候,

尼克修斯

最佳答案

根据 Boost documentation about factorial :

 BOOST_STATIC_ASSERT(!boost::is_integral<T>::value); 
// factorial<unsigned int>(n) is not implemented
// because it would overflow integral type T for too small n
// to be useful. Use instead a floating-point type,
// and convert to an unsigned type if essential, for example:
// unsigned int nfac = static_cast<unsigned int>(factorial<double>(n));
// See factorial documentation for more detail.

intunsigned int 的阶乘版本尚未实现,因为即使是小值也会导致溢出。

例如,13 的阶乘为 6227020800,这超出了 unsigned int 的最大限制(如果 int 的长度为 4 个字节,则为 4294967295)。

您必须使用doublefloat 来计算阶乘。

关于c++ - 错误 C2338: !boost::is_integral<T>::value with boost,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19544846/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com