boost::function
オブジェクトを使用してポインターの値を設定したいVisualStudio2008 C++03プロジェクトがあります。このようなもの:
boost::function< void( int* ) > SetValue;
boost::function< int*() > GetValue;
int* my_value_;
SetValue = boost::bind( my_value_, _1 ); // how should this look?
GetValue = boost::bind( my_value_ ); // and this?
int v;
SetValue( &v );
assert( my_value_ == &v );
int* t = GetValue();
assert( t == my_value_ );
これを行う方法はありますか、それとも次のような中間関数が必要ですか?
void DoSetValue( int* s, int* v ) { s = v; };
SetValue = boost::bind( DoSetValue, my_value_, _1 );
ありがとう