我声明并定义了一个执行比较的函数:
template <class KEY, class VALUE>
bool compareFlatMapElements(
typename SortedPairsVector<KEY, VALUE>::ElementType& first,
typename SortedPairsVector<KEY, VALUE>::ElementType& second);
// Compares the specified 'first' and 'second' using
// 'bsl::less<KEY>' to compare the values stored in 'first()' of
// each pair held by the 'FlatMap_Element.
template <class KEY, class VALUE>
inline
bool compareFlatMapElements(
typename SortedPairsVector<KEY, VALUE>::ElementType& first,
typename SortedPairsVector<KEY, VALUE>::ElementType& second)
{
return first.data().first < second.data().first;
}
之后我尝试在sort
中使用它 std::sort(d_data.begin(), d_data.end(), compareFlatMapElements);
是什么导致以下错误,我如何修复它?
error: no matching function for call to 'sort(..., ..., <unresolved overloaded function type>)'
没有模板参数的独立函数compareFlatMapElements
如果d_data
的键类型为Key
, d_data
的值类型为Value
,
std::sort(d_data.begin(), d_data.end(), compareFlatMapElements<Key, Value>);