0
使用模板時,隨着++這個模板用C是重載操作< <錯誤:對不明確的超負荷「運營商<<」在C++
template<typename T> cEnvir& operator<<(const T& t) {out << t; return *this;}
我有這個明確的錯誤。
error: ambiguous overload for ‘operator<<’ in ‘((cEnvir*)this)->cEnvir::out << t’
/usr/include/c++/4.2.1/ostream:169: note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char, _Traits = std::char_traits<char>] <near match>
/usr/include/c++/4.2.1/ostream:173: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
...
這個問題看起來像typename T編譯器不能決定匹配。 當我註釋掉/* out << t; */
時,編譯工作正常。
我該如何解決這個問題?我使用gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
。
我們可以有更多的信息。例如,您在哪裏聲明瞭此模板,以及涉及的不同元素的類型是什麼? – Morwenn 2013-04-24 09:02:54
發佈整個錯誤。我們無法看到這個模板實例中有什麼「T」。 – Oktalist 2014-03-31 18:13:03