Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;对字符串中的字符进行反向排序_C++_String_Sorting_Stl - Fatal编程技术网

C++ C++;对字符串中的字符进行反向排序

C++ C++;对字符串中的字符进行反向排序,c++,string,sorting,stl,C++,String,Sorting,Stl,有很多代码可以按字典顺序对字符串数组进行排序,但我找不到一个能按字典顺序对一个字符串中的字符进行反向排序的代码。到目前为止,我发现在中使用std::sort(): 在/usr/lib/gcc/i686 pc linux gnu/4.5.1/../../../../../../../include/c++/4.5.1/算法:63:0中包含的文件中, 来自项目cpp:1: prog.cpp:在函数“void std::uu insertion_sort(_RandomAccessIterator,_

有很多代码可以按字典顺序对字符串数组进行排序,但我找不到一个能按字典顺序对一个字符串中的字符进行反向排序的代码。到目前为止,我发现在
中使用
std::sort()

在/usr/lib/gcc/i686 pc linux gnu/4.5.1/../../../../../../../include/c++/4.5.1/算法:63:0中包含的文件中,
来自项目cpp:1:
prog.cpp:在函数“void std::uu insertion_sort(_RandomAccessIterator,_RandomAccessIterator,_Compare)[with u RandomAccessIterator=u gnu_cxx::u normal_迭代器,_Compare=反向比较器]”中:
/usr/lib/gcc/i686 pc linux gnu/4.5.1/../../../../../../include/c++/4.5.1/bits/stl_algo.h:2192:4:从“void std::_final_insertion_sort(_RandomAccessIterator,_RandomAccessIterator,_Compare)[with_RandomAccessIterator=_gnuCXX::_normal_迭代器,_Compare=ReverseComparator]实例化
/usr/lib/gcc/i686 pc linux gnu/4.5.1/../../../../../../include/c++/4.5.1/bits/stl_algo.h:5252:4:从“void std::sort(_RAIter,_RAIter,_RAIter,_Compare,_Compare)[与_RAIter=_gnuCXX::_normal迭代器,_Compare=ReverseComparator]实例化
prog.cpp:12:49:从此处实例化
prog.cpp:6:11:错误:“bool ReverseComparator::operator()(T,T)[with T=char]”是私有的
/usr/lib/gcc/i686 pc linux gnu/4.5.1/../../../../../../../include/c++/4.5.1/bits/stl_algo.h:2125:4:错误:在此上下文中
prog.cpp:在函数“void std::u heap_select(_RandomAccessIterator,_RandomAccessIterator,_RandomAccessIterator,_Compare)[with _RandomAccessIterator=u gnu_cxx::u normal_迭代器,_Compare=ReverseComparator]:
/usr/lib/gcc/i686 pc linux gnu/4.5.1/../../../../../../../include/c++/4.5.1/bits/stl_algo.h:5100:7:从“void std::partial_sort(_RAIter,_RAIter,_RAIter,_RAIter,_RAIter,_Compare,_Compare)[with _RAIter=_gnuCXX::_normaliter,_迭代器,_Compare=反向比较器]实例化
/usr/lib/gcc/i686 pc linux gnu/4.5.1/../../../../../../../include/c++/4.5.1/bits/stl_algo.h:2297:8:从“void std::_introsort_loop(_RandomAccessIterator,_RandomAccessIterator,_Size,_Compare,_Compare)[with_RandomAccessIterator=_gnuCxx::_normal_normal(iterator,_Size=int,)Compare=ReverseComparator]实例化
/usr/lib/gcc/i686 pc linux gnu/4.5.1/../../../../../../../include/c++/4.5.1/bits/stl_algo.h:5250:4:从“void std::sort(_RAIter,_RAIter,_RAIter,_Compare,_Compare)[与_RAIter=_gnuCXX::_normaliter,_Compare=ReverseComparator]实例化
prog.cpp:12:49:从此处实例化
prog.cpp:6:11:错误:“bool ReverseComparator::operator()(T,T)[with T=char]”是私有的
/usr/lib/gcc/i686 pc linux gnu/4.5.1/../../../../../../../include/c++/4.5.1/bits/stl_algo.h:1914:2:错误:在此上下文中
prog.cpp:在函数“void std::uu move_median_first(_Iterator,_Iterator,_Iterator,_Compare)[with _Iterator=u gnu_cxx::u normal_Iterator,_Compare=ReverseComparator]:
/usr/lib/gcc/i686 pc linux gnu/4.5.1/../../../../../../../include/c++/4.5.1/bits/stl_algo.h:2260:7:从“_randomAccessIteratorstd::_unguarded_partition_pivot(_RandomAccessIterator,_RandomAccessIterator,_cxx,_Compare)[with_RandomAccessIterator=_gnuCxx:::_normal_Compare=ReverseComparator]”实例化
/usr/lib/gcc/i686 pc linux gnu/4.5.1/../../../../../include/c++/4.5.1/bits/stl_algo.h:2302:62:从“void std::_introsort_loop(_RandomAccessIterator,_RandomAccessIterator,_Size,_Compare)[with_RandomAccessIterator=_gnuCxx::_normal_迭代器,_Size=int,_Compare=ReverseComparator]实例化
/usr/lib/gcc/i686 pc linux gnu/4.5.1/../../../../../../../include/c++/4.5.1/bits/stl_algo.h:5250:4:从“void std::sort(_RAIter,_RAIter,_RAIter,_Compare,_Compare)[与_RAIter=_gnuCXX::_normaliter,_Compare=ReverseComparator]实例化
prog.cpp:12:49:从此处实例化
prog.cpp:6:11:错误:“bool ReverseComparator::operator()(T,T)[with T=char]”是私有的
/usr/lib/gcc/i686 pc linux gnu/4.5.1/../../../../../../../include/c++/4.5.1/bits/stl_algo.h:108:7:错误:在此上下文中
prog.cpp:6:11:错误:“bool ReverseComparator::operator()(T,T)[with T=char]”是私有的
/usr/lib/gcc/i686 pc linux gnu/4.5.1/../../../../../../../include/c++/4.5.1/bits/stl_algo.h:110:4:错误:在此上下文中
/usr/lib/gcc/i686 pc linux gnu/4.5.1/../../../../../../../include/c++/4.5.1/bits/stl_algo.h:2260:7:从“_randomAccessIteratorstd::_unguarded_partition_pivot(_RandomAccessIterator,_RandomAccessIterator,_cxx,_Compare)[with_RandomAccessIterator=_gnuCxx:::_normal_Compare=ReverseComparator]”实例化
/usr/lib/gcc/i686 pc linux gnu/4.5.1/../../../../../include/c++/4.5.1/bits/stl_algo.h:2302:62:从“void std::_introsort_loop(_RandomAccessIterator,_RandomAccessIterator,_Size,_Compare)[with_RandomAccessIterator=_gnuCxx::_normal_迭代器,_Size=int,_Compare=ReverseComparator]实例化
/usr/lib/gcc/i686 pc linux gnu/4.5.1/../../../../../../../include/c++/4.5.1/bits/stl_algo.h:5250:4:从“void std::sort(_RAIter,_RAIter,_RAIter,_Compare,_Compare)[与_RAIter=_gnuCXX::_normaliter,_Compare=ReverseComparator]实例化
prog.cpp:12:49:从此处实例化
prog.cpp:6:11:错误:“bool ReverseComparator::operator()(T,T)[with T=char]”是私有的
/usr/lib/gcc/i686 pc linux gnu/4.5.1/../../../../../../../include/c++/4.5.1/bits/stl_algo.h:112:9:错误:在此上下文中
prog.cpp:6:11:错误:“bool ReverseComparator::operator()(T,T)[with T=char]”是私有的
/usr/lib/gcc/i686 pc linux gnu/4.5.1/../../../../../../../include/c++/4.5.1/bits/stl_algo.h:115:12:错误:在此上下文中
prog.cpp:6:11:错误:“bool ReverseComparator::operator()(T,T)[with T=char]”是私有的
/usr/lib/gcc/i686 pc linux gnu/4.5.1/../../../../../../../include/c++/4.5.1/bits/stl_algo.h:117:12:错误:在此上下文中
prog.cpp:在函数“\u RandomAccessIterator std::\u无保护的分区(\u RandomAccessIterator,\u RandomAccessIterator,const,Tp&,\u Compare)[与\u RandomAccessIterator=\u gnu(cxx::\u normal)迭代器,\u Tp char,\u Compare=reversecomperator]”中:
/usr/lib/gcc/i686 pc-linux-gnu/4.5.1/../../../../../../../../include/c++/4.5.1/bits/stl_-algo.h
template <typename T>
class ReverseComparator{
     bool operator()(T l, T r){return !(l < r);}
};
//.....later
std::sort(str.begin(), str.end(), comparator);
In file included from /usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/algorithm:63:0,
                 from prog.cpp:1:
prog.cpp: In function 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]':
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:2192:4:   instantiated from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:5252:4:   instantiated from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
prog.cpp:12:49:   instantiated from here
prog.cpp:6:11: error: 'bool ReverseComparator<T>::operator()(T, T) [with T = char]' is private
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:2125:4: error: within this context
prog.cpp: In function 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]':
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:5100:7:   instantiated from 'void std::partial_sort(_RAIter, _RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:2297:8:   instantiated from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Size = int, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:5250:4:   instantiated from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
prog.cpp:12:49:   instantiated from here
prog.cpp:6:11: error: 'bool ReverseComparator<T>::operator()(T, T) [with T = char]' is private
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:1914:2: error: within this context
prog.cpp: In function 'void std::__move_median_first(_Iterator, _Iterator, _Iterator, _Compare) [with _Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]':
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:2260:7:   instantiated from '_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:2302:62:   instantiated from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Size = int, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:5250:4:   instantiated from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
prog.cpp:12:49:   instantiated from here
prog.cpp:6:11: error: 'bool ReverseComparator<T>::operator()(T, T) [with T = char]' is private
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:108:7: error: within this context
prog.cpp:6:11: error: 'bool ReverseComparator<T>::operator()(T, T) [with T = char]' is private
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:110:4: error: within this context
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:2260:7:   instantiated from '_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:2302:62:   instantiated from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Size = int, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:5250:4:   instantiated from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
prog.cpp:12:49:   instantiated from here
prog.cpp:6:11: error: 'bool ReverseComparator<T>::operator()(T, T) [with T = char]' is private
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:112:9: error: within this context
prog.cpp:6:11: error: 'bool ReverseComparator<T>::operator()(T, T) [with T = char]' is private
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:115:12: error: within this context
prog.cpp:6:11: error: 'bool ReverseComparator<T>::operator()(T, T) [with T = char]' is private
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:117:12: error: within this context
prog.cpp: In function '_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, const _Tp&, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Tp = char, _Compare = ReverseComparator<char>]':
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:2261:78:   instantiated from '_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:2302:62:   instantiated from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Size = int, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:5250:4:   instantiated from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
prog.cpp:12:49:   instantiated from here
prog.cpp:6:11: error: 'bool ReverseComparator<T>::operator()(T, T) [with T = char]' is private
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:2229:4: error: within this context
prog.cpp:6:11: error: 'bool ReverseComparator<T>::operator()(T, T) [with T = char]' is private
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:2232:4: error: within this context
prog.cpp: In function 'void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]':
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:2133:6:   instantiated from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:2192:4:   instantiated from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:5252:4:   instantiated from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
prog.cpp:12:49:   instantiated from here
prog.cpp:6:11: error: 'bool ReverseComparator<T>::operator()(T, T) [with T = char]' is private
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:2083:7: error: within this context
In file included from /usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:62:0,
                 from /usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/algorithm:63,
                 from prog.cpp:1:
prog.cpp: In function 'void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Distance = int, _Tp = char, _Compare = ReverseComparator<char>]':
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_heap.h:434:4:   instantiated from 'void std::make_heap(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:1912:7:   instantiated from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:5100:7:   instantiated from 'void std::partial_sort(_RAIter, _RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:2297:8:   instantiated from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Size = int, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:5250:4:   instantiated from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
prog.cpp:12:49:   instantiated from here
prog.cpp:6:11: error: 'bool ReverseComparator<T>::operator()(T, T) [with T = char]' is private
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_heap.h:303:4: error: within this context
prog.cpp: In function 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Distance = int, _Tp = char, _Compare = ReverseComparator<char>]':
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_heap.h:316:7:   instantiated from 'void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Distance = int, _Tp = char, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_heap.h:434:4:   instantiated from 'void std::make_heap(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:1912:7:   instantiated from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:5100:7:   instantiated from 'void std::partial_sort(_RAIter, _RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:2297:8:   instantiated from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Size = int, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:5250:4:   instantiated from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
prog.cpp:12:49:   instantiated from here
prog.cpp:6:11: error: 'bool ReverseComparator<T>::operator()(T, T) [with T = char]' is private
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_heap.h:180:7: error: within this context
In file included from /usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/algorithm:63:0,
                 from prog.cpp:1:
prog.cpp: In function 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]':
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:2192:4:   instantiated from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
/usr/lib/gcc/i686-pc-linux-gnu/4.5.1/../../../../include/c++/4.5.1/bits/stl_algo.h:5252:4:   instantiated from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >, _Compare = ReverseComparator<char>]'
prog.cpp:12:49:   instantiated from here
prog.cpp:6:11: error: 'bool ReverseComparator<T>::operator()(T, T) [with T = char]' is private
'bool ReverseComparator<T>::operator()(T, T) [with T = char]' is private
#include <algorithm>
#include <string>

template <typename T>
class ReverseComparator{
    public: //forgot this
     bool operator()(T l, T r){return !(l < r);}
};

int main() {
    std::string str = "HELLO";
    ReverseComparator<char> comparator;
    std::sort(str.begin(), str.end(), comparator);
}
template <typename T>
class ReverseComparator{
public:
     bool operator()(const T& l, const T& r){return (r < l);}
};

std::sort(str.begin(), str.end(), ReverseComparator());
std::sort(str.begin(), str.end(), [](const T& l, const T& r){return (r < l);});
std::sort(str.begin(), str.end(), std::greater<char>());
std::sort(str.rbegin(), str.rend());
std::sort(s.begin(), s.end(), ReverseComparator<char>());
template <typename T>
class ReverseComparator {
public:
    bool operator()(T lhs, T rhs) const { return rhs < lhs; }
};