質問
私は、すべてが基本的に同じフォームを持っている多くの関数を使用して、C ++クラスをテストしています。
ClassUnderTest t;
DATATYPE data = { 0 };
try
{
t.SomeFunction( &data );
}
catch( const SomeException& e )
{
// log known error
}
catch( ... )
{
// log unknown error
}
これらの多くがあるので、私は私が重い持ち上げのほとんどを行うための関数を書くと思った:
template< typename DATA, typename TestFunction >
int DoTest( TestFunction test_fcn )
{
DATA data = { 0 };
try
{
test_fcn( &data );
}
catch( const SomeException& e )
{
// log known error
return FAIL;
}
catch( ... )
{
// log unknown error
return FAIL;
}
return TRUE;
}
ClassUnderTest t;
DoTest< DATATYPE >( boost::bind( &ClassUnderTest::SomeFunction, boost::ref( t ) ) );
しかし、コンパイラはこれが良い考えだと私に同意していないようです...
Warning 1 warning C4180: qualifier applied to function type has no meaning; ignored c:\boost\boost_1_41_0\boost\bind\bind.hpp 1657
Warning 2 warning C4180: qualifier applied to function type has no meaning; ignored c:\boost\boost_1_41_0\boost\bind\mem_fn.hpp 318
Warning 3 warning C4180: qualifier applied to function type has no meaning; ignored c:\boost\boost_1_41_0\boost\bind\mem_fn.hpp 326
Warning 4 warning C4180: qualifier applied to function type has no meaning; ignored c:\boost\boost_1_41_0\boost\bind\mem_fn.hpp 331
Warning 5 warning C4180: qualifier applied to function type has no meaning; ignored c:\boost\boost_1_41_0\boost\bind\mem_fn.hpp 345
Warning 6 warning C4180: qualifier applied to function type has no meaning; ignored c:\boost\boost_1_41_0\boost\bind\mem_fn.hpp 350
Warning 7 warning C4180: qualifier applied to function type has no meaning; ignored c:\boost\boost_1_41_0\boost\bind\mem_fn.hpp 362
Error 8 fatal error C1001: An internal error has occurred in the compiler. c:\boost\boost_1_41_0\boost\bind\mem_fn.hpp 328
Visual Studio 2008 SP1を使用しています。誰かが私が間違っていることを指摘できれば、私はそれを感謝します。
ありがとう、ポール
解決
エラーはコードにあり、ではありません bind
. 。あなたは議論を期待していない機能者を渡します。あなたの電話の代わりに、そうしてください
DoTest< DATATYPE >( boost::bind( &ClassUnderTest::SomeFunction, &t, _1) );
省略した場合 _1
それから bind
ゼロアーグメント関数オブジェクトを作成し、メンバー関数(データポインターが予想される)は、呼び出されたときに1つの引数を見逃します bind
.
所属していません StackOverflow