I have a structure
struct position {
    int x;
    int y;
};
and a vector pos of such structures.
When I try to check whether a certain element is present in this vector, I use
    auto it = std::find(pos.begin(), pos.end(), {x,y});
This, however, only works, when I explicitly pass the constructor to std::find() function, i.e.
    auto it = std::find(pos.begin(), pos.end(), position({x,y}));
Otherwise, I get compiler error
    std::find: no matching overloaded function found
Why is that? Is it because compiler cannot deduce the type of {x,y} in the line above?
Aucun commentaire:
Enregistrer un commentaire