内部编译器错误和boost :: bind

Pau*_*ulH 2 c++ boost bind c1001

我正在测试一个C++类,其中包含许多基本相同形式的函数:

ClassUnderTest t;

DATATYPE data = { 0 };
try
{
    t.SomeFunction( &data );
}
catch( const SomeException& e )
{
    // log known error
}
catch( ... )
{
    // log unknown error
}
Run Code Online (Sandbox Code Playgroud)

由于有很多这些,我以为我会写一个功能来完成大部分繁重的工作:

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 ) ) );
Run Code Online (Sandbox Code Playgroud)

但是,编译器似乎并不认同这是一个好主意...

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
Run Code Online (Sandbox Code Playgroud)

我正在使用Visual Studio 2008 SP1.如果有人能够指出我做错了什么,我将不胜感激.

谢谢,PaulH

Joh*_*itb 7

错误在您的代码中,而不是在bind.你传递了一个不期望任何参数的仿函数.而不是你的电话,做

DoTest< DATATYPE >( boost::bind( &ClassUnderTest::SomeFunction, &t, _1) );
Run Code Online (Sandbox Code Playgroud)

如果省略_1然后bind将创建一个零参数函数对象和成员函数(这需要一个数据指针)将错过一个参数时叫bind.