2010-03-03 4 views

답변

9

이것은 BOOST_CHECK_THROW 매크로이고 Foo(bar)은 문으로 확장 되었기 때문에 발생합니다. 컴파일러는이 명령문을보고 기본 선언자가 필요한 변수 선언 Foo bar;으로 해석합니다. 즉

BOOST_CHECK_THROW(Foo temp(bar), std::logic_error); 

BOOST_CHECK_THROW

try 
{ 
    Foo(bar); 
    // ... fail test ... 
} 
catch(std::logic_error) 
{ 
    // ... pass test ... 
} 

처럼 뭔가 확장되고 컴파일러라는 변수의 선언으로 Foo(bar); 해석된다

이 솔루션은 변수의 이름을 지정하는 것입니다 바. 하나는 간단한 프로그램으로이를 확인할 수 있습니다

struct Test 
{ 
    Test(int *x) {} 
}; 

int main() 
{ 
    int *x=0; 
    Test(x); 
    return 0; 
} 

는 사실

test.cpp: In function ‘int main()’: 
test.cpp:10: error: conflicting declaration ‘Test x’ 
test.cpp:9: error: ‘x’ has a previous declaration as ‘int* x’ 
+0

++ g과 함께 다음과 같은 오류를 제공한다. 감사. –