boost 1.57在VC2012裡編譯出錯以及解決
阿新 • • 發佈:2019-02-19
最新發布的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 深圳