인 경우 BOOST_CHECK_EQUAL (쌍, 쌍)을 시도하면 gcc는 쌍을위한 스트림 연산자를 찾지 않습니다. 재미있는 점은 std :: out이 연산자를 찾는다는 것입니다.BOOST_CHECK_EQUAL 쌍이 <int, int>이고 사용자 지정 연산자가 <<
ostream& operator<<(ostream& s, const pair<int,int>& p) {
s << '<' << p.first << ',' << p.second << '>';
return s;
}
BOOST_AUTO_TEST_CASE(works)
{
pair<int,int> expected(5, 5);
pair<int,int> actual (5, 5);
std::cout << expected << std::endl;
std::cout << actual << std::endl;
BOOST_CHECK(actual == expected);
}
BOOST_AUTO_TEST_CASE(no_work)
{
pair<int,int> expected(5, 5);
pair<int,int> actual (5, 5);
BOOST_CHECK_EQUAL(actual, expected);
}
이 나던 오류 컴파일 :
... instantiated from here
../boost-atp/release/include/boost/test/test_tools.hpp:326:9: error: no match for ‘operator<<’ in ‘ostr << t’
사용자 정의 유형에 대한 자신의 인쇄를 정의의 * 새로운 * 방법이 여기에 설명 : https://stackoverflow.com/a/44810846/1617295, 그리고 [이는 그 코드는 시작해야한다 공식 문서] (http://www.boost.org/doc/libs/1_66_0/libs/test/doc/html/boost_test/test_output/test_tools_support_for_logging/testing_tool_output_disable.html)를 참조하십시오. – Raffi
@ 라피 (Raffi)이 질문은이 사본이 중복 된 것처럼 보입니다. 어쩌면 그것을 중복으로 표시하고 여기에 답을 옮겨서 사용자가 점프하지 않도록 할 수 있습니까? 나는 그것을 받아 들일 수있다. 감사! – nishantjr