Я пытаюсь скомпилировать следующий код с помощью clang, но получаю следующую ошибку.
Мне интересно, почему использование sort
из класса list
будет работать, но не std :: sort
.
#include <list>
#include <iostream>
int main(){
std::string strings[] = {"hello", "nihao", "byebye", "yo"};
std::list<std::string> cars(strings, strings+sizeof(strings) / sizeof(char **));
// cars.sort(std::less<std::string>()); // compiles fine and produce a sorted list
std::sort(cars.rbegin(), cars.rend(), std::less<std::string>() ); // this one won't compile
for (std::list<std::string>::iterator it = cars.begin(); it != cars.end(); ++it)
std::cout << *it << " - ";
std::cout << std::endl;
return 0;
}
/ usr / include / c ++ / 4.2.1 / bits / stl_iterator.h: 320: 25: ошибка: недопустимые операнды для двоичного выражения ('iterator_type' (также известного как 'std: : _List_iterator> ') и' iterator_type ') {return __y.base () - __x.base (); }