G
Gianni Mariani
Can anyone enligten me why I get the "ambiguous overload" error from the
code below:
friendop.cpp: In function `int main()':
friendop.cpp:36: ambiguous overload for `std::basic_ostream<char,
std::char_traits<char> >& << Thing&' operator
friendop.cpp:27: candidates are: std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>&, const Thing&) [with
w_char_type = char, w_traits = std::char_traits<char>]
friendop.cpp:14: std::basic_ostream<_CharT, _Traits>&
std:perator<<(std::basic_ostream<_CharT, _Traits>&, const Thing&)
[with
w_char_type = char, w_traits = std::char_traits<char>]
friendop.cpp:27: std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>&, const Thing&) [with
w_char_type = char, w_traits = std::char_traits<char>]
The code:
#include <iostream>
class Thing;
namespace std {
template<
typename w_char_type,
class w_traitsbasic_ostream<w_char_type, w_traits>& operator << (
basic_ostream<w_char_type, w_traits> & o_ostream,
const ::Thing & value
);
}// namespace std
class Thing
{
template<
typename w_char_type,
class w_traitsfriend std::basic_ostream<w_char_type, w_traits>& operator << (
std::basic_ostream<w_char_type, w_traits> & o_ostream,
const ::Thing & value
);
};
int main()
{
Thing b;
std::cout << "b = " << b;
}
code below:
friendop.cpp: In function `int main()':
friendop.cpp:36: ambiguous overload for `std::basic_ostream<char,
std::char_traits<char> >& << Thing&' operator
friendop.cpp:27: candidates are: std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>&, const Thing&) [with
w_char_type = char, w_traits = std::char_traits<char>]
friendop.cpp:14: std::basic_ostream<_CharT, _Traits>&
std:perator<<(std::basic_ostream<_CharT, _Traits>&, const Thing&)
[with
w_char_type = char, w_traits = std::char_traits<char>]
friendop.cpp:27: std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>&, const Thing&) [with
w_char_type = char, w_traits = std::char_traits<char>]
The code:
#include <iostream>
class Thing;
namespace std {
template<
typename w_char_type,
class w_traitsbasic_ostream<w_char_type, w_traits>& operator << (
basic_ostream<w_char_type, w_traits> & o_ostream,
const ::Thing & value
);
}// namespace std
class Thing
{
template<
typename w_char_type,
class w_traitsfriend std::basic_ostream<w_char_type, w_traits>& operator << (
std::basic_ostream<w_char_type, w_traits> & o_ostream,
const ::Thing & value
);
};
int main()
{
Thing b;
std::cout << "b = " << b;
}