【发布时间】:2022-11-01 11:22:51
【问题描述】:
有人可以解释为什么这段代码会产生。无论我将地图值设置为什么,我都能将错误缩小到该段。
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.33.31629\include\xstddef(117,1): 错误 C2784: 'bool std::operator <(std::nullptr_t,const std::shared_ptr<_Ty> &) noexcept': 无法从 'const _Ty' 推导出 'const std::shared_ptr<_Ty> &' 的模板参数
struct Vector2i { int x; int y; }; std::map<Vector2i, Chunk*> map{}; map.insert({ Vector2i{0,0}, nullptr });谢谢 :)
我尝试注释掉 Vector2i 结构的所有其他实例,并且该段似乎是导致此错误的唯一位置。
【问题讨论】:
-
std::map 使用比较函数对其项目进行排序。如果您不指定默认值是
std::less<key>其中 key 是您的Vector2i
标签: c++