簡體   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