回 帖 发 新 帖 刷新版面

主题:bind2nd函数的疑惑

template<class T, class U>
class CFindMapValueBinary : public binary_function<T, U, bool>
{
public:
    bool operator()(typename map<T, U>::value_type iter, U &value)
    {
        return iter.second == value;
    }
};

int main()
{
    binder2nd<CFindMapValueBinary<int, int> > it = bind2nd(CFindMapValueBinary<int, int>(),15);
    find_if(intMap.begin(), intMap.end(), it);

   return 0;
}

这么写好像不对,请问正确的写法是怎么样的?

回复列表 (共1个回复)

沙发


实验了下,正确写法:
template<class T, class U>
class CFindMapValueBinary : public binary_function<typename map<T, U>::value_type, U, bool>
{
public:
    bool operator()(const typename map<T, U>::value_type iter, const U& value) const
    {
        return iter.second == value;
    }
};

int main()
{
    map<int, int> intIntMap;
    binder2nd<CFindMapValueBinary<int, int> > it = bind2nd(CFindMapValueBinary<int, int>(),15);
    find_if(intIntMap.begin(), intIntMap.end(), it);
    return 0;
}

我来回复

您尚未登录,请登录后再回复。点此登录或注册