0

考虑这个片段:

#include <vector>
#include <algorithm>
#include <boost/function.hpp>
#include <boost/bind.hpp>

template<typename PODType>
class SomeClass
{
public:
    SomeClass() : m_pred(boost::bind(&SomeClass<PODType>::someMethodA, this, _1))
    {
    }

    bool someMethodA(const PODType& elem)
    {
        return false;
    }

    bool someMethodB(const std::vector<PODType>& vec)
    {
        return (std::find_if(vec.begin(), vec.end(), m_pred(_1)) != vec.end());
    }

private:
    boost::function<bool(PODType)> m_pred;
};


int main(int argc, char* argv[])
{
    SomeClass<int> obj;
    std::vector<int> v;
    obj.someMethodB(v);

    return 0;
}

编译器给出

error: no match for call to '(boost::function<bool(int)>) (boost::arg<1>&)'
note:   no known conversion for argument 1 from 'boost::arg<1>' to 'int'

为线return (std::find_if(vec.begin(), vec.end(), m_pred(_1)));

我正在尝试someMethodA在成员谓词中进行find_if调用。

4

1 回答 1

3

路过m_pred,没必要m_pred(_1)

于 2013-09-17T16:21:47.643 回答