![](/img/trans.png)
[英]compiler error on calling boost::bind() inside boost::thread constructor
[英]Internal compiler error and boost::bind
我正在測試具有許多函數的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。 如果有人指出我在做什么錯,我將不勝感激。
謝謝PaulH
錯誤在您的代碼中,而不在bind
。 您傳遞的函子不包含任何參數。 代替您的電話
DoTest< DATATYPE >( boost::bind( &ClassUnderTest::SomeFunction, &t, _1) );
如果省略_1
則bind
將創建一個零參數函數對象,而該成員函數(期望一個數據指針)在被bind
調用時將丟失一個參數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.