2

以下代码在我要创建仿函数对象的行处引发错误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;

}

编译器给了我一组模板错误和

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

这似乎是主要错误。尽管如此,我不知道这里有什么问题以及如何解决它。

4

1 回答 1

3

问题已解决:我使用了错误的语法。

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

作品。

于 2010-07-13T20:49:00.037 回答