繁体   English   中英

错误:没有匹配的函数可以调用&#39;sort(...,…, <unresolved overloaded function type> )&#39;

[英]error: no matching function for call to 'sort(…, …, <unresolved overloaded function type>)'

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

  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;
  }

然后,我稍后尝试在某种程度上使用它

      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>);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM