为什么我对mem_fun_ref的调用没有“匹配功能”?

| 我有一些代码,其中类从基类继承。 该基类具有一个函数,该函数在运行时应调用要由子代实现的函数。也就是说,所有子代的通用算法都相同,但是步骤的实现应有所不同。
template<class T>
class Foo
{
    public:
        Foo(T y):y(y) { for(int i; i < 10; ++i) x.push_back(i); };
    protected:
        virtual bool IsOk(T, int)=0;
        void Run()
        {
            vector<int>::iterator it, bound;
            for(int i; i < 10; ++i)
            {
                cout << \"step \" << i << endl;
                bound = partition(x.begin(), x.end(), bind2nd(mem_fun_ref(&Foo<T>::IsOk), i));
                for (it=x.begin(); it!=bound; ++it)
                    cout << \"  \" << *it;
            };
        };
    private:
        vector<int>x;
        T y;
};

class Bar : public Foo<int>
{
    public:
        Bar():Foo<int>(50){this->Run();};
        bool IsOk(int x , int y) {return x == y;}

};
但是,这样做时,我收到以下错误消息:
no matching function for call to \'mem_fun_ref(bool (Foo<int>::*)(int, int))\'
谁能为我提供一些有关我在做什么的见解?     
已邀请:
以下是
mem_fun_ref
的原型
template <class S, class T>
  mem_fun_ref_t<S,T> mem_fun_ref (S (T::*f)());

template <class S, class T, class A>
  mem_fun1_ref_t<S,T,A> mem_fun_ref (S (T::*f)(A));

template <class S, class T>
  const_mem_fun_ref_t<S,T> mem_fun_ref (S (T::*f)() const);

template <class S, class T, class A>
  const_mem_fun1_ref_t<S,T,A> mem_fun_ref (S (T::*f)(A) const);
您的
mem_fun_ref(bool (Foo<int>::*)(int, int))
档案与其中任何一项都匹配,因此会出现错误。     
mem_fun_ref
仅适用于带有一个或不带参数的函数。要实现您的想法,您将必须使用
boost::bind
(C ++ 0x标准库的一部分)。     

要回复问题请先登录注册