Interner Compiler -Fehler und Boost :: Bind
Frage
Ich teste eine C ++ - Klasse mit einer Reihe von Funktionen, die im Grunde genommen die gleiche Form haben:
ClassUnderTest t;
DATATYPE data = { 0 };
try
{
t.SomeFunction( &data );
}
catch( const SomeException& e )
{
// log known error
}
catch( ... )
{
// log unknown error
}
Da es viele davon gibt, dachte ich, ich würde eine Funktion schreiben, um den größten Teil des schweren Hebens zu erledigen:
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 ) ) );
Aber der Compiler scheint mir nicht zuzustimmen, dass dies eine gute Idee ist ...
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
Ich verwende Visual Studio 2008 SP1. Wenn jemand darauf hinweisen kann, was ich falsch mache, würde ich es schätzen.
Danke, Paulh
Lösung
Der Fehler ist in Ihrem Code, nicht in bind
. Sie verabschieden einen Funkgerät, der keine Argumente erwartet. Anstelle Ihres Anrufs tun Sie
DoTest< DATATYPE >( boost::bind( &ClassUnderTest::SomeFunction, &t, _1) );
Wenn Sie weglassen _1
dann bind
Erstellt ein Null-Argument-Funktionsobjekt, und die Mitgliedsfunktion (die einen Datenzeiger erwartet) wird ein Argument verpassen, wenn er aufgerufen wird bind
.