samedi 30 juillet 2016

std::sort - indirection requires pointer operand

I want to sort a vector of Sprite objects

std::function<bool(const Sprite&,const Sprite&)> fn;
fn = [](auto&& a, auto&& b) ->bool { return a.pos.x > b.pos.x; };
std::sort(sprites.begin(), sprites.end(), fn);

/usr/bin/../lib/gcc/x86_64-redhat-linux/5.3.1/../../../../include/c++/5.3.1/bits/predefined_ops.h:123:31: fatal error: indirection requires pointer operand ('Sprite' invalid) { return bool(_M_comp(*__it1, *__it2)); }

But if I inline the sorting function there is no error. What is the problem?

Aucun commentaire:

Enregistrer un commentaire