views:

29

answers:

1

The following code throws an error at the line where I want to create a functor object of Test::fun2:

#include <boost/shared_ptr.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>

using namespace boost;

class Test
{

public:
 float fun1() { return 0.0f; }
 void fun2( float x ) {}

};

int main( int argc, char* argv[] )
{

 shared_ptr<Test> p = shared_ptr<Test>( new Test );

 function<float(void)> f1 = bind( &Test::fun1, p );
 function<void(float)> f2 = bind( &Test::fun2, p );

 return 1;

}

The compiler gives me a set of template errors and

`void (Test::*)(float)' is not a class, struct, or union type

which seems to be the main error. Nevertheless I have no idea what's the problem here and how to solve it.

+1  A: 

Problem solved: I used the wrong syntax.

function f2 = bind( &Test::fun2, p, _1 );

works.

rallex
you can accept your own answer.
Sam Miller