c++ - Using binder1st with custom functor -
i'd bind first argument of print functor 0:
#include<iostream> #include<functional> using namespace std; class print : public std::binary_function<int,int,void>{ public: void operator()(int val1, int val2) { cout << val1 + val2 << endl; } }; int main() { print print; binder1st(print,0) f; //this line 16 f(3); //should print 3 }
the program above (based on example c++ primer plus) not compile:
line16 : error : missing template arguments before ‘(’ token
what wrong?
i don't want use c++11 nor boost features.
edited: operator() return type has been changed bool void simplicity
as error message says, missing template arguments before (
want
std::binder1st<print> f(print, 0);
however, need make operator()
const follows
bool operator()(int val1, int val2) const
finally, function needs return something.
Comments
Post a Comment