언급 한 테스트 프레임 워크에서 내 유형을 출력하고 싶습니다. Google clearly states 가능합니다. Google Test Framework 출력 사용자 정의 유형
namespace foo {
class Bar { ... };
// It's important that PrintTo() is defined in the SAME
// namespace that defines Bar. C++'s look-up rules rely on that.
void PrintTo(const Bar& bar, ::std::ostream* os) {
*os << bar.DebugString(); // whatever needed to print bar to os
}
} // namespace foo
As mentioned earlier, the printer is extensible. That means you can teach it to do a better job at printing your particular type than to dump the bytes. To do that, define << for your type:
error: no match for ‘operator<<’ in ‘* os << val’ /usr/include/c++/4.4/ostream:108: note: candidates are:
그것은과 제안의 긴 목록 뒤에 나의 말에 operator<<
과부하 :
std::ostream& Navmii::ProgrammingTest::operator<<(std::ostream&, Navmii::ProgrammingTest::AsciiString&)
누군가가 도와 줄 수 있습니까?
감사합니다. 이것은 아마도 최악의 경우는 아니지만 컴파일러의 메시지는 매우 혼란 스러울 수 있습니다. – vehsakul
참. 특정 이름의 함수가 하나 뿐인 경우 컴파일러는 예상과 일치하지 않는 매개 변수를 알려줌으로써 도움이 될 수 있습니다. 그러나 하나 이상의 함수가 요청 된 이름 (이 경우'operator <<')과 일치 할 때, 모든 단일 함수가 주어진 사용을 만족시키지 못하는 이유를 설명하려고하면 오류 메시지가 훨씬 더 다루기 힘들어집니다. C++에는 "가장 근접한 불일치"에 대한 개념이 없습니다. 만약 그렇다면, const가 아닌 함수가 "꽤 가깝다"는 것을 알아 낸 다음, 그 단일 함수가 코드에서 사용 된 시도와 어떻게 다른지를 보여 줬을 것입니다. –