错误:没有匹配函数来调用'sort(...,...,<unresolved overloaded function type>)'

GBl*_*ney 1 c++

我声明然后定义一个执行比较的函数:

  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;
  }
Run Code Online (Sandbox Code Playgroud)

然后我尝试在排序中使用它

      std::sort(d_data.begin(), d_data.end(), compareFlatMapElements);
Run Code Online (Sandbox Code Playgroud)

是什么导致以下错误,我该如何解决?

error: no matching function for call to 'sort(..., ..., <unresolved overloaded function type>)'
Run Code Online (Sandbox Code Playgroud)

R S*_*ahu 5

没有compareFlatMapElements模板参数,没有自由站立功能.

如果键的类型d_dataKey和值类型d_dataValue,

使用

std::sort(d_data.begin(), d_data.end(), compareFlatMapElements<Key, Value>);
Run Code Online (Sandbox Code Playgroud)