boost::gregorio::date构造函数,带有警告C4244

boost::gregorian::date constructor with Warning C4244

本文关键字:警告 C4244 构造函数 gregorio date boost      更新时间:2024-09-29

此代码片段在我的测试项目中运行良好。但它与我的工作项目上的警告一起编译

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;

是一个修复。

相关文章: