доброго времени суток.
при попытке переопределить operator<<() для потока:
| Код | #include <iostream>
std::ostream& operator<< (std::ostream& o, int v) { return o; }
int main() { int v = 0; return (std::cout << v << std::endl).good(); }
|
получаю сообщение:
| Цитата | bb988fcf420c7ec16e3e2192ff27cfa2/source.cpp: In function 'int main()': bb988fcf420c7ec16e3e2192ff27cfa2/source.cpp:9:25: error: ambiguous overload for 'operator<<' in 'std::cout << v' /usr/local/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/ostream:108:7: note: candidates are: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>] <near match> /usr/local/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../../include/c++/4.5.0/ostream:117:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ios_type& (*)(std::basic_ostream<_CharT, _Traits>::__ios_type&)) [with _CharT = char, _Traits = std::char_traits<char>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>, std::basic_ostream<_CharT, _Traits>::__ios_type = std::basic_ios<char>] <near match>
и т.д..
|
причину понимаю. но как побороть? |