Std :: sort - indirection requires a pointer pointer

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 embed the sort function, no error occurs. What is the problem?

I am using clang version 3.7.0, but the error does not seem to appear in gcc.

+4
source share

Source: https://habr.com/ru/post/1649613/


All Articles