c++ - 使用 std::accumulate(v.begin(), v.end(), 0) 发出警告;
问题描述
为什么我会收到警告C4244 '=': conversion from '__int64' to '_Ty', possible loss of data
?此外,auto
而不是LONGLONG
产生此警告。
std::vector<LONGLONG>& v = m_vecEstimatedTime;
LONGLONG nEstimatedTimeTotal = std::accumulate(v.begin(), v.end(), 0); // warning C4244 '=': conversion from '__int64' to '_Ty'
解决方案
返回类型和汇总值的类型std::accumulate
由传递的初始值决定。因为0
它会int
。
如果类型应该是LONGLONG
,您可以将初始值指定为:
LONGLONG nEstimatedTimeTotal = std::accumulate(v.begin(), v.end(), static_cast<LONGLONG>(0));
推荐阅读
- swift - 从 Swift 4 中返回的排序字典数组中访问键
- javascript - 在 Express 中拒绝访问 server.js
- python - 使用 re 和 urllib.request 模块
- mysql - mysql 使用 NOT IN 的最快方法
- signalr - Signalr - ConnectionId 的格式不正确
- asp.net-mvc - MVC 后值空
- spring-boot - 长时间运行@Scheduled Job 导致数据库连接泄漏
- unity3d - 如何使用 .mtl 文件更改金属光滑度
- uwp - 对 Microsoft Store API 的请求始终返回空的产品/订阅列表
- javascript - 由 uuid 更新的 javascript 对象数组