Je teste une classe C++ avec un certain nombre de fonctions qui ont tous essentiellement la même forme:erreur du compilateur interne et boost :: bind
ClassUnderTest t;
DATATYPE data = { 0 };
try
{
t.SomeFunction(&data);
}
catch(const SomeException& e)
{
// log known error
}
catch(...)
{
// log unknown error
}
Comme il y a beaucoup de ceux-ci, que je pensais avoir écrire une fonction pour faire la plupart du levage de charges lourdes:
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)));
Mais, le compilateur ne semble pas d'accord avec moi que ce soit une bonne idée ...
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
J'utilise Visual Studio 2008 SP1. Si quelqu'un peut signaler ce que je fais mal, je l'apprécierais.
Merci, PaulH
Je pouvais ignorer les avertissements, mais j'espérais que tout ce que je pourrais faire pour corriger les avertissements produirait aussi du code qui ne ferait pas planter le compilateur. – PaulH
Alors, y a-t-il un moyen de rendre ce C++ 03 valide? – PaulH
@PaulH, je ne sais pas assez sur 'bind' pour dire comment cela fonctionne en interne, et pas assez sur MSVC++ pour dire pourquoi il se bloque soit. Je suis désolé. Peut-être qu'un autre peut éclairer la question ici. Peut-être essayer de passer '& t' au lieu de' ref (t) 'ou essayer de passer' boost :: mem_fn (& Class :: Function) 'au premier paramètre de bind au lieu de' & Class :: Function' directement. –