boost::gregorio::date构造函数,带有警告C4244
boost::gregorian::date constructor with Warning C4244
此代码片段在我的测试项目中运行良好。但它与我的工作项目上的警告一起编译
auto current_date = boost::gregorian::day_clock::local_day();
const auto nMinYear = current_date.year(); const auto nMonth = current_date.month(); const auto nDay = current_date.day();
const auto nMinYear1 = nMinYear + 1;
boost::gregorian::date holidayDate1(nMinYear1, nMonth, nDay);
在holidayDate1施工线上。
警告C4244"argument":从"unsigned int"转换为"unsigne"短',可能丢失数据
我的测试项目在boost-1.72上,工作项目在1.75上,都在Visual Studio 2019上。
我尝试使用grep_year来包装nMinYear1——holidayDate1(grep_year(nMinYear1 ))
——它不编译。
编辑:
我刚刚尝试了一个强制铸造可以绕过它,
boost::gregorian::date holidayDate1((unsigned short)nMinYear, (unsigned short)nMonth, (unsigned short)nDay);
但我不明白为什么会发出警告。
的类型
nMinYear + 1
将是CCD_ 2。所以nMinYear1
是一个const unsigned int
,当它在boost::gregorian::date
构造函数中使用时,编译器会发出警告。
decltype(nMinYear) nMinYear1 = nMinYear + 1;
是一个修复。
相关文章:
- 警告处理为错误这里有什么问题
- 使用动态分配的数组会导致代码分析发出虚假的C6386缓冲区溢出警告
- cppcheck在const std::string[]上引发警告
- GCC对可能有效的代码抛出init list生存期警告
- 如何在BST的这个简单递归实现中消除警告
- 关于std::move的使用,是否有编译警告
- g++ 在某个类成员未初始化时不发出警告
- 如何避免警告C4244:从'ULONGLONG'转换为"双倍",可能丢失数据
- 如何禁用Visual Studio警告C4244,用于std::vector复制或使用隐式缩小转换进行赋值
- 警告 C4244:'argument':从 'double' 转换为"浮点数",可能会丢失数据 - C++
- 为什么VC C4244警告(可能丢失数据)专门处理'int'?
- 警告 C4244:"参数":从"double"转换为"int",可能会丢失数据
- 警告 1 警告 C4244:"参数":从"time_t"转换为"无符号 int",可能会丢失数据以及其他错误
- C4244对复合加法赋值的4级警告,但对和和赋值没有警告
- 警告 C4244:"参数":从"double"转换为"const int",可能会丢失数据
- 警告 C4244:'argument':从 'time_t' 转换为"无符号 int",可能会丢失数据 -- C++
- 警告 C4244:'argument':从 'int' 转换为"浮点",可能会丢失数据 (C++)
- 编译器警告在boost crc.hpp与Visual c++(错误C4244)
- 警告 C4244 \ '=':从 'int' 转换为"char",可能会丢失数据?
- <在哪里转换?>警告 C4244:'initializing':从 '__int64' 转换为"int",可能会丢失数据