2010-03-04 2 views
2

나는 모두가 기본적으로 같은 형태가 다수의 기능을 가진 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

답변

7

오류는하지 bind에, 코드입니다. 인수를 기대하지 않는 펑터를 전달합니다. 대신 전화, 당신은 _1 다음 bind가 0 인수 함수 객체를 생성합니다 생략하면

DoTest<DATATYPE>(boost::bind(&ClassUnderTest::SomeFunction, &t, _1)); 

를 수행하고 bind에 의해 호출 할 때 (데이터 포인터를 예상) 멤버 함수는 하나 개의 인수를 그리워합니다.

+0

경고를 무시할 수는 있지만 경고를 수정하기 위해 할 수있는 것이 무엇이든 컴파일러 충돌을 일으키지 않는 코드도 생성되기를 바랬습니다. – PaulH

+0

그럼이 C++ 03을 유효하게 만들 수있는 방법이 있습니까? – PaulH

+1

@ PaulHH, 나는 내부적으로 어떻게 작동하는지 말하기에'bind'에 대해서 충분히 알지 못한다. MSVC++에 대해서는 왜 그렇게 부숴 졌는지 말하기에는 충분하지 않다. 죄송 해요. 어쩌면 다른 문제가 여기에 더 많은 것을 밝힐 수 있습니다. 어쩌면'ref (t)'대신에'& t'를 전달하거나'& Class :: Function' 대신 직접 bind의 첫 번째 매개 변수에'boost :: mem_fn (& Class :: Function)'을 전달해보십시오. –

관련 문제