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

問題解決: 間違った構文を使用しました。

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

動作します。

于 2010-07-13T20:49:00.037 に答える