could someone please explain why this code produces. i was able to narrow the error to this segment regardless of what I set the map value to.
C:Program FilesMicrosoft Visual Studio2022CommunityVCToolsMSVC14.33.31629includexstddef(117,1): error C2784: ‘bool std::operator <(std::nullptr_t,const std::shared_ptr<_Ty> &) noexcept’: could not deduce template argument for ‘const std::shared_ptr<_Ty> &’ from ‘const _Ty’
struct Vector2i
{
int x;
int y;
};
std::map<Vector2i, Chunk*> map{};
map.insert({ Vector2i{0,0}, nullptr });
thanks 🙂
I tried commenting out all other instances of the Vector2i struct and this segment seemed to be the only place that causes this error.
2
Answers
The std::map is an ordered container, and therefore requires keys to provide a "less-than" operator for comparison. This can be provided in the map’s template arguments, or it can be implicit if you have defined
operator<
for your type.You should provide comparison operator to your map. Here is some ways.
Define operator< inside struct.
Define outside the struct.
Define struct comparator and pass to constructor of map.
Using lambda function.