带有boost 1.50的Visual Studio C ++ 2005/2010:警告C4267

时间:2012-08-13 13:14:02

标签: c++ boost warnings

我无法阻止此警告..

...\boost\asio\impl\io_service.ipp(46) : warning C4267: 'argument' : conversion from 'size_t' to 'std::numeric_limits<unsigned int>::_Ty', possible loss of data

也许你有

  1. 对此的解释
  2. 防止投掷的解决方案: - )
  3. 麻烦,

    亚历

1 个答案:

答案 0 :(得分:4)

  

对此的解释

怀疑这是一个64位版本,size_t将是64位,unsigned int将是32位:

std::cout << sizeof(unsigned int) << "\n"; // Output '4' on both x86 and x64
std::cout << sizeof(size_t)       << "\n"; // Output '4' on x86
                                           // Output '8' on x64
  

防止投掷的解决方案

添加编译器标志/Wd4267以禁用此警告。但是,这会禁用项目中您可能不喜欢的所有源的警告。另一种方法是使用#pragma warning

#pragma warning(disable: 4267)
#include <boost-header-files>
#pragma warning(default: 4267)
相关问题