2013-10-23 28 views
1

我试图在oder中使用boost来计算factorial。我不知道为什么,但VS2013显示我编译错误。错误C2338:!boost :: is_integral <T> :: value with boost

任何人有一些想法吗?

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错误C2338:提高:: is_integral ::值d:\用户\ XXXXXX \下载\ boost_1_55_0b1 \ boost_1_55_0b1 \提升\数学\ special_functions \阶乘。 HPP 32 1个APPS

编辑:

代码由双取代INT:

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

错误消息:

ERREUR 1个错误C2039: 'assert_not_arg':n'est PAS membre德 '的boost :: MPL' d:\用户\ XXXXX \下载\ boost_1_55_0b1 \ boost_1_55_0b1 \提升\ MPL \ aux_ \预处理\平原\ arg.hpp 45 1

ERREUR 2错误C3861: 'assert_not_arg':identificateur introuvable d:\用户\ XXXXX \下载\ boost_1_55_0b1 \ boost_1_55_0b1 \提高\ MPL \ aux_ \预处理\平原\ arg.hpp 45 1

非常感谢,

最好的问候,

Nixeus

+0

请发布完整的错误消息。它包含有关什么时候出现“T”的信息。 – Angew

+0

这里完成:) –

回答

4

根据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的最大限制(如果整数是4个字节,则为4294967295)。

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

+0

你好,你是对的,我几分钟前看到这个!我修改我的代码,以处理双重,但我有另一个错误信息。 Erreur error C2039:'assert_not_arg':n'est pas membre de'boost :: mpl'\t d:\ users \ XXXXX \ downloads \ boost_1_55_0b1 \ boost_1_55_0b1 \ boost \ mpl \ aux_ \ preprocessed \ plain \ arg.hpp –

+0

根据这个问题,似乎Visual Studio与某些功能不兼容:http://stackoverflow.com/questions/17440810/how-do-i-build-boost-with-new-visual-studio-2013-预览 – xorguy

+0

是的,我也看到了这个,使用boost 1.53,没关系! –

相关问题