Visual Studio C++ 2005/2010 with boost 1.50: warning C4267



我无法阻止此警告。

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

也许你得到了

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

亚历克斯

对此的解释

怀疑这是一个 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)

最新更新