From 2f0849fef4883a9cb9e785ae0f90a6d0d00d2959 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 11 Feb 2009 18:06:37 +0000 Subject: Fixes the "ambiguous overload" compiler error when a mock function takes an argument that supports streaming to basic_ostream. --- include/gmock/gmock-printers.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/gmock/gmock-printers.h b/include/gmock/gmock-printers.h index eae6e52d..759aa347 100644 --- a/include/gmock/gmock-printers.h +++ b/include/gmock/gmock-printers.h @@ -116,8 +116,19 @@ class TypeWithoutFormatter { // to simplify the implementation, as much code in 'internal' needs to // use << in STL, which would conflict with our own << were it defined // in 'internal'. -template -::std::ostream& operator<<(::std::ostream& os, const T& x) { +// +// Note that this operator<< takes a generic std::basic_ostream type instead of the more restricted std::ostream. If +// we define it to take an std::ostream instead, we'll get an +// "ambiguous overloads" compiler error when trying to print a type +// Foo that supports streaming to std::basic_ostream, as the compiler cannot tell whether +// operator<<(std::ostream&, const T&) or +// operator<<(std::basic_stream, const Foo&) is more +// specific. +template +::std::basic_ostream& operator<<( + ::std::basic_ostream& os, const T& x) { TypeWithoutFormatter::value>:: PrintValue(x, &os); return os; -- cgit v1.2.3