필터 펑터를 입력 문자열의 값에 따라 클래스의 멤버 메소드 중 하나와 매핑하려고합니다.오류 : boost-bind를 boost-function으로 사용할 때 'operator []'에 모호한 오버로드가 발생했습니다.
#include <iostream>
#include <map>
#include <boost/function.hpp>
#include <boost/cstdint.hpp>
#include <boost/assign.hpp>
#include <boost/bind.hpp>
typedef boost::function < bool(std::map<std::string, std::string>, std::string) > MyFilterFunctor;
class MyClass
{
public:
bool FilterFunction1(std::map<std::string, std::string> myMap, std::string filterValue)
{
//do something
return true;
}
};
int main() {
MyFilterFunctor myFilter = boost::bind(&MyClass::FilterFunction1, _1, _2, _3);
return 0;
}
그리고 내 오류 :
/usr/include/boost/bind/bind.hpp:375:
error: ambiguous overload for ‘operator[]’ in ‘a[boost::_bi::storage3<A1, A2, boost::arg<I> >::a3_ [with A1 = boost::arg<1>, A2 = boost::arg<2>, int I = 3]]’
편집 : 는 내 질문에 제안 된 답변의 제안에 약간 나의 예를 단순화. boost :: bind에 인수로 MyClass()를 전달해야하므로 제안 된 코드 세그먼트의 컴파일 오류가 해결됩니다. 그러나, 내 코드 구조가 주어진다면 그렇게 할 수는 없습니다. '이'내가 제공 제안되고있는
struct X
{
int f(int);
}
int main()
{
boost::bind(&X::f, 1); // error, X::f takes two arguments
boost::bind(&X::f, _1, 1); // OK
}
는 암시 적 처리를 _1 매개 변수를 사용 안 : 내가 무슨 짓을하는 부스트 :: 바인드 설명서에서이 예제는 다른 이유를 알고 싶습니다 명시 적으로 MyClass()?
filterKey - string? – ForEveR
예, filterKey는 std :: string입니다. 더 명확하게하기 위해 변수 선언을 편집 할 것입니다. – user1535568
사람들이 직접 붙여 넣기를 복사하고 스스로를 시도하고 재생할 수있는 자체 포함 가능한 컴파일 가능한 최소 예가 도움이 될 수 있습니다. – PlasmaHH