binder2nd
은 unary_function
으로부터 유도된다.C++의 STL unary_function은 gcc 4.7.x에서 구현 된 것처럼 가상 함수를 가질 수 있습니까?
다음 코드는 작동하지 않습니다
greater<int> g;
//greater is derived from binary_function
//bind2nd returns binder2nd object and binder2nd is derived from unary_function
const unary_function<int,bool> &greater_than_0 = bind2nd(g, 0);
// base class reference type holding reference to derived class object
remove_if(lst.begin(), lst.end(), greater_than_0);
//does not work
을 다음과 같은 코드가 작동하는 반면 :
greater<int> g;
const binder2nd< greater<int> > &greater_than_0 = bind2nd(g, 0);
remove_if(lst.begin(), lst.end(), greater_than_0);
unary_function
에 더미 가상 함수를 가지고 도움이 될 것입니다 그래서 첫 번째 코드 스 니펫이 작동합니다. STL의 사용을 향상시킬 수 있습니까?
이러한 함수는 일반 ['std :: bind'] (http://en.cppreference.com/w/cpp/utility/functional/bind)에서 더 이상 사용되지 않습니다. –
당신이'std :: function'을 원한다고 생각합니다, 다형성입니다 –
가상 함수가 어떻게 도움이 될지 모르겠습니다 ... 사실 저는 여러분이'가상'을 전혀 언급하지 않았다고 생각합니다. 초과 적재? –