您的位置:首页 > 其它

boost 1.57在VC2012里编译出错以及解决

2014-11-17 12:36 211 查看
最新发布的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;
}

蔡军生 QQ: 9073204 深圳
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐