簡體   English   中英

沒有重載函數需要2個參數(functors)

[英]no overloaded function takes 2 arguments(functors)

我在嘗試為我的Heap數據結構實現自定義比較器支持時遇到了問題,這是我希望它看起來像的樣子:

    template <class T, class Pred = std::less<T>>
    class ConcurrentPriorityQueue {
    private:

        template <class T>
        class Node
        {
        private:
            T data;
            bool operator < (const Node<T>& t) {
            return Pred(data, t.data);
         }
            };
     };

這是我要使用的比較函子:

struct comp {
            bool operator () (const std::pair<int, fn_type> &p1,
                const std::pair<int, fn_type> &p2) const{
                return p1.first < p2.first;
            }
        };

ConcurrentPriorityQueue<std::pair<int, fn_type>, comp> fqueue;

一切對我來說似乎都不錯,但是我遇到了錯誤

錯誤2錯誤C2661:'ThreadPool :: comp :: comp':沒有重載函數使用2個參數c:\\ users \\ usr \\ documents \\ visual studio 2013 \\ projects \\ secondtask \\ queue.hpp。 你能幫我這個忙嗎?

Pred是指一種類型,而不是該類型的實例。


當前,您在執行Pred(data, t.data)時嘗試調用Pred類型的構造函數,您首先必須創建Pred的實例才能在其上調用匹配的operator() (...)

下面的示例創建一個Pred類型的臨時實例,然后調用其operator()

        return Pred () (data, t.data); // 1) create a temporary instance of `Pred`
                                       // 2) call its operator() with `data` and `t.data`

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM