#include <functional>
class Greater : public binary_function<Airline, int, bool> {
public:
bool operator ()(const Airline& lhs, int value) const {
return lhs.getPlanes() > value;
}
};
Jag vill använda algoritmen find_if på en vektor av min klass Airline (som har ett heltal no_of_planes som attribut). Mitt kriterie för find_if är att värdet no_of_planes skall vara större än 4. Jag har en egen funktionsklass som heter Greater:
class Greater{
public:
bool operator()(Airline& lhs, int value){
return (lhs.getPlanes() > value);
}
};
när jag anropar find_if:
vector<Airline>::iterator it99 = find_if(Airport.begin(), Airport.end(), bind2nd(Greater(), 4));
får jag ett antal kompileringsfel
Compiling...
test.cpp
c:\program\microsoft visual studio\vc98\include\functional(175) : error C2039: 'first_argument_type' : is not a member of 'Greater'
d:\greater.h(8) : see declaration of 'Greater'
D:\test.cpp(52) : see reference to class template instantiation 'std::binder2nd<class Greater>' being compiled
c:\program\microsoft visual studio\vc98\include\functional(175) : error C2065: 'first_argument_type' : undeclared identifier
D:\\test.cpp(52) : see reference to class template instantiation 'std::binder2nd<class Greater>' being compiled
c:\program\microsoft visual studio\vc98\include\functional(176) : error C2039: 'result_type' : is not a member of 'Greater'
d:\greater.h(8) : see declaration of 'Greater'
D:\test.cpp(52) : see reference to class template instantiation 'std::binder2nd<class Greater>' being compiled
c:\program\microsoft visual studio\vc98\include\functional(176) : error C2065: 'result_type' : undeclared identifier
D:\test.cpp(52) : see reference to class template instantiation 'std::binder2nd<class Greater>' being compiled
c:\program\microsoft visual studio\vc98\include\functional(176) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.
test.obj - 5 error(s), 0 warning(s)
Jag misstänker att min funktionsklass är felkonstruerad. Någon som är bra på funktionsklasser, std-algoritmer predikat, osv? I synnerhet bind2nd...
