AMDG Ahmed Badran wrote:
I was trying to use boost function/bind to bind the first argument of a member function that takes two arguments, when I got into a compilation error that I can't quite decipher or understand, below is a sample representation of the problem, and then there's the compilation error, am I doing something incorrectly here?
I have tried removing the boost::mem_fn instantiation with no difference.
#include
#include #include #include <iostream> using namespace std; using namespace boost;
class my_class { public: void test(bool b) { cout << "got " << b << endl; } private: };
int main() { my_class c; boost::function1
test_fn; boost::bind(&my_class::test, &c, _2); /* causes a compilation error */ test_fn = boost::bind<void>(boost::mem_fn(&my_class::test), &c, _2);
Use _1 instead of _2. The placeholder number indicates the first argument to the function object created by bind. You're only passing a single bool argument in, so only _1 is a valid placeholder. In Christ, Steven Watanabe