首页 > 代码库 > boost 1.57在VC2012里编译出错以及解决
boost 1.57在VC2012里编译出错以及解决
最新发布的boost版本是在2014年11月3日发布,由于项目里使用,就立即更新为最新版本的库,这样也可以让可能出现的BUG减到最少。
不过在更新这库之后,发现原来可以编译通过的项目,而现在不能通过了,提示错误如下:
transform_width.hpp(156): error C2589: ‘(‘ : illegal token on right side of ‘::‘
通过仔细地查看transform_width.hpp文件,发现是其中的std::min使用有问题,因为min函数的两个传入参数类型不一样,这样进行模板
匹配时,就找不到相应的模板。这行代码如下:
unsigned int i = std::min(missing_bits, m_remaining_bits);
通过函数的代码来分析,missing_bits是unsigned int类型,而m_remaining_bits是CHAR类型,导致编译出错。知道了出错的原因,就容易
解决了。把这行代码修改为:
unsigned int i = std::min<unsigned int>(missing_bits, m_remaining_bits);
相关的模板代码:
template<
class Base,
int BitsOut,
int BitsIn,
class CharType
>
void transform_width<Base, BitsOut, BitsIn, CharType>::fill() {
unsigned int missing_bits = BitsOut;
m_buffer_out = 0;
do{
if(0 == m_remaining_bits){
if(m_end_of_sequence){
m_buffer_in = 0;
m_remaining_bits = missing_bits;
}
else{
m_buffer_in = * this->base_reference()++;
m_remaining_bits = BitsIn;
}
}
// append these bits to the next output
// up to the size of the output
修改之前:
unsigned int i = std::min(missing_bits, m_remaining_bits);
把这行修改为:
unsigned int i = std::min<unsigned int>(missing_bits, m_remaining_bits);
// shift interesting bits to least significant position
base_value_type j = m_buffer_in >> (m_remaining_bits - i);
// and mask off the un interesting higher bits
// note presumption of twos complement notation
j &= (1 << i) - 1;
// append then interesting bits to the output value
m_buffer_out <<= i;
m_buffer_out |= j;
// and update counters
missing_bits -= i;
m_remaining_bits -= i;
}while(0 < missing_bits);
m_buffer_out_full = true;
不过在更新这库之后,发现原来可以编译通过的项目,而现在不能通过了,提示错误如下:
transform_width.hpp(156): error C2589: ‘(‘ : illegal token on right side of ‘::‘
通过仔细地查看transform_width.hpp文件,发现是其中的std::min使用有问题,因为min函数的两个传入参数类型不一样,这样进行模板
匹配时,就找不到相应的模板。这行代码如下:
unsigned int i = std::min(missing_bits, m_remaining_bits);
通过函数的代码来分析,missing_bits是unsigned int类型,而m_remaining_bits是CHAR类型,导致编译出错。知道了出错的原因,就容易
解决了。把这行代码修改为:
unsigned int i = std::min<unsigned int>(missing_bits, m_remaining_bits);
相关的模板代码:
template<
class Base,
int BitsOut,
int BitsIn,
class CharType
>
void transform_width<Base, BitsOut, BitsIn, CharType>::fill() {
unsigned int missing_bits = BitsOut;
m_buffer_out = 0;
do{
if(0 == m_remaining_bits){
if(m_end_of_sequence){
m_buffer_in = 0;
m_remaining_bits = missing_bits;
}
else{
m_buffer_in = * this->base_reference()++;
m_remaining_bits = BitsIn;
}
}
// append these bits to the next output
// up to the size of the output
修改之前:
unsigned int i = std::min(missing_bits, m_remaining_bits);
把这行修改为:
unsigned int i = std::min<unsigned int>(missing_bits, m_remaining_bits);
// shift interesting bits to least significant position
base_value_type j = m_buffer_in >> (m_remaining_bits - i);
// and mask off the un interesting higher bits
// note presumption of twos complement notation
j &= (1 << i) - 1;
// append then interesting bits to the output value
m_buffer_out <<= i;
m_buffer_out |= j;
// and update counters
missing_bits -= i;
m_remaining_bits -= i;
}while(0 < missing_bits);
m_buffer_out_full = true;
}
蔡军生 QQ: 9073204 深圳
boost 1.57在VC2012里编译出错以及解决
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。