title: Unable to use ostream << overload with stringstream no known conversion for argument 1
body: <p>I'm when trying to write to a stringstream using a overload of &lt;&lt; for ostream gcc fails with:</p>
  
  <p>error: no match for 'operator&lt;&lt;' (operand types are 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&amp;()}' and 'const Test')</p>
  
  <p>As far as I can tell the operator is defined, I've used similar code with stringstream (input operator for other classes where I overload for istream) with out any problems using the same compiler.</p>
  
  <p>Example Code:</p>
  
  <pre><code>// Header
  #include &lt;istream&gt;
  #include &lt;ostream&gt;
  
  class Test {
  public:
      Test* Clone() const { return onClone(); }
      friend std::istream&amp; operator &gt;&gt; (std::istream&amp; lhs, Test&amp; rhs) { rhs.onLoad(lhs); return lhs; }
      friend std::ostream&amp; operator &lt;&lt; (std::ostream&amp; lhs, const Test&amp; rhs) { rhs.onSave(lhs); return lhs; }
  private:
      virtual void onLoad(std::istream&amp; in) {}
      virtual void onSave(std::ostream&amp; out) const {}
      Test* Test::onClone() const;
  };
  
  // Source
  #include &lt;sstream&gt;
  
  Test* Test::onClone() const
  {
      Test * tmp = new Test();
      std::stringstream&amp; buf();
      buf &lt;&lt; (*this); //!&lt; ERROR HERE
      buf &gt;&gt; (*tmp);
      return tmp;
  }
  </code></pre>
  
  <p>Filtered Build Output:</p>
  
  <pre><code>g++.exe -Wzero-as-null-pointer-constant -std=c++14 -m64 -Wcast-align -Wundef -Wfloat-equal -Winline -Wunreachable-code -Wswitch-enum -Wswitch-default -Weffc++ -Wzero-as-null-pointer-constant -pg -g -D_WIN32 -D_UNICODE  -Iinclude -c test.cpp -o obj\Debug\test.o
  test.cpp: In member function 'Test* Test::onClone() const':
  test.cpp:23:9: error: no match for 'operator&lt;&lt;' (operand types are 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}' and 'const Test')
       buf &lt;&lt; (*this); //!&lt; ERROR HERE
           ^
  In file included from %LibaryPath%/istream:39:0,
                   from test.cpp:2:
  %LibaryPath%/ostream:628:5: note: candidate: template&lt;class _CharT, class _Traits, class _Tp&gt; std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;_CharT, _Traits&gt;&amp;&amp;, const _Tp&amp;)
       operator&lt;&lt;(basic_ostream&lt;_CharT, _Traits&gt;&amp;&amp; __os, const _Tp&amp; __x)
       ^
  %LibaryPath%/ostream:628:5: note:   template argument deduction/substitution failed:
  test.cpp:23:18: note:   mismatched types 'std::basic_ostream&lt;_CharT, _Traits&gt;' and 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}'
       buf &lt;&lt; (*this); //!&lt; ERROR HERE
                    ^
  In file included from %LibaryPath%/istream:39:0,
                   from test.cpp:2:
  %LibaryPath%/ostream:574:5: note: candidate: template&lt;class _Traits&gt; std::basic_ostream&lt;char, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;char, _Traits&gt;&amp;, const unsigned char*)
       operator&lt;&lt;(basic_ostream&lt;char, _Traits&gt;&amp; __out, const unsigned char* __s)
       ^
  %LibaryPath%/ostream:574:5: note:   template argument deduction/substitution failed:
  test.cpp:23:18: note:   mismatched types 'std::basic_ostream&lt;char, _Traits&gt;' and 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}'
       buf &lt;&lt; (*this); //!&lt; ERROR HERE
                    ^
  In file included from %LibaryPath%/istream:39:0,
                   from test.cpp:2:
  %LibaryPath%/ostream:569:5: note: candidate: template&lt;class _Traits&gt; std::basic_ostream&lt;char, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;char, _Traits&gt;&amp;, const signed char*)
       operator&lt;&lt;(basic_ostream&lt;char, _Traits&gt;&amp; __out, const signed char* __s)
       ^
  %LibaryPath%/ostream:569:5: note:   template argument deduction/substitution failed:
  test.cpp:23:18: note:   mismatched types 'std::basic_ostream&lt;char, _Traits&gt;' and 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}'
       buf &lt;&lt; (*this); //!&lt; ERROR HERE
                    ^
  In file included from %LibaryPath%/istream:39:0,
                   from test.cpp:2:
  %LibaryPath%/ostream:556:5: note: candidate: template&lt;class _Traits&gt; std::basic_ostream&lt;char, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;char, _Traits&gt;&amp;, const char*)
       operator&lt;&lt;(basic_ostream&lt;char, _Traits&gt;&amp; __out, const char* __s)
       ^
  %LibaryPath%/ostream:556:5: note:   template argument deduction/substitution failed:
  test.cpp:23:18: note:   mismatched types 'std::basic_ostream&lt;char, _Traits&gt;' and 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}'
       buf &lt;&lt; (*this); //!&lt; ERROR HERE
                    ^
  In file included from %LibaryPath%/ostream:638:0,
                   from %LibaryPath%/istream:39,
                   from test.cpp:2:
  %LibaryPath%/bits/ostream.tcc:321:5: note: candidate: template&lt;class _CharT, class _Traits&gt; std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;_CharT, _Traits&gt;&amp;, const char*)
       operator&lt;&lt;(basic_ostream&lt;_CharT, _Traits&gt;&amp; __out, const char* __s)
       ^
  %LibaryPath%/bits/ostream.tcc:321:5: note:   template argument deduction/substitution failed:
  test.cpp:23:18: note:   mismatched types 'std::basic_ostream&lt;_CharT, _Traits&gt;' and 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}'
       buf &lt;&lt; (*this); //!&lt; ERROR HERE
                    ^
  In file included from %LibaryPath%/istream:39:0,
                   from test.cpp:2:
  %LibaryPath%/ostream:539:5: note: candidate: template&lt;class _CharT, class _Traits&gt; std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;_CharT, _Traits&gt;&amp;, const _CharT*)
       operator&lt;&lt;(basic_ostream&lt;_CharT, _Traits&gt;&amp; __out, const _CharT* __s)
       ^
  %LibaryPath%/ostream:539:5: note:   template argument deduction/substitution failed:
  test.cpp:23:18: note:   mismatched types 'std::basic_ostream&lt;_CharT, _Traits&gt;' and 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}'
       buf &lt;&lt; (*this); //!&lt; ERROR HERE
                    ^
  In file included from %LibaryPath%/istream:39:0,
                   from test.cpp:2:
  %LibaryPath%/ostream:519:5: note: candidate: template&lt;class _Traits&gt; std::basic_ostream&lt;char, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;char, _Traits&gt;&amp;, unsigned char)
       operator&lt;&lt;(basic_ostream&lt;char, _Traits&gt;&amp; __out, unsigned char __c)
       ^
  %LibaryPath%/ostream:519:5: note:   template argument deduction/substitution failed:
  test.cpp:23:18: note:   mismatched types 'std::basic_ostream&lt;char, _Traits&gt;' and 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}'
       buf &lt;&lt; (*this); //!&lt; ERROR HERE
                    ^
  In file included from %LibaryPath%/istream:39:0,
                   from test.cpp:2:
  %LibaryPath%/ostream:514:5: note: candidate: template&lt;class _Traits&gt; std::basic_ostream&lt;char, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;char, _Traits&gt;&amp;, signed char)
       operator&lt;&lt;(basic_ostream&lt;char, _Traits&gt;&amp; __out, signed char __c)
       ^
  %LibaryPath%/ostream:514:5: note:   template argument deduction/substitution failed:
  test.cpp:23:18: note:   mismatched types 'std::basic_ostream&lt;char, _Traits&gt;' and 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}'
       buf &lt;&lt; (*this); //!&lt; ERROR HERE
                    ^
  In file included from %LibaryPath%/istream:39:0,
                   from test.cpp:2:
  %LibaryPath%/ostream:508:5: note: candidate: template&lt;class _Traits&gt; std::basic_ostream&lt;char, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;char, _Traits&gt;&amp;, char)
       operator&lt;&lt;(basic_ostream&lt;char, _Traits&gt;&amp; __out, char __c)
       ^
  %LibaryPath%/ostream:508:5: note:   template argument deduction/substitution failed:
  test.cpp:23:18: note:   mismatched types 'std::basic_ostream&lt;char, _Traits&gt;' and 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}'
       buf &lt;&lt; (*this); //!&lt; ERROR HERE
                    ^
  In file included from %LibaryPath%/istream:39:0,
                   from test.cpp:2:
  %LibaryPath%/ostream:502:5: note: candidate: template&lt;class _CharT, class _Traits&gt; std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;_CharT, _Traits&gt;&amp;, char)
       operator&lt;&lt;(basic_ostream&lt;_CharT, _Traits&gt;&amp; __out, char __c)
       ^
  %LibaryPath%/ostream:502:5: note:   template argument deduction/substitution failed:
  test.cpp:23:18: note:   mismatched types 'std::basic_ostream&lt;_CharT, _Traits&gt;' and 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}'
       buf &lt;&lt; (*this); //!&lt; ERROR HERE
                    ^
  In file included from %LibaryPath%/istream:39:0,
                   from test.cpp:2:
  %LibaryPath%/ostream:497:5: note: candidate: template&lt;class _CharT, class _Traits&gt; std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;_CharT, _Traits&gt;&amp;, _CharT)
       operator&lt;&lt;(basic_ostream&lt;_CharT, _Traits&gt;&amp; __out, _CharT __c)
       ^
  %LibaryPath%/ostream:497:5: note:   template argument deduction/substitution failed:
  test.cpp:23:18: note:   mismatched types 'std::basic_ostream&lt;_CharT, _Traits&gt;' and 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}'
       buf &lt;&lt; (*this); //!&lt; ERROR HERE
                    ^
  In file included from %LibaryPath%/bits/ios_base.h:46:0,
                   from %LibaryPath%/ios:42,
                   from %LibaryPath%/istream:38,
                   from test.cpp:2:
  %LibaryPath%/system_error:209:5: note: candidate: template&lt;class _CharT, class _Traits&gt; std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;_CharT, _Traits&gt;&amp;, const std::error_code&amp;)
       operator&lt;&lt;(basic_ostream&lt;_CharT, _Traits&gt;&amp; __os, const error_code&amp; __e)
       ^
  %LibaryPath%/system_error:209:5: note:   template argument deduction/substitution failed:
  test.cpp:23:18: note:   mismatched types 'std::basic_ostream&lt;_CharT, _Traits&gt;' and 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}'
       buf &lt;&lt; (*this); //!&lt; ERROR HERE
                    ^
  In file included from %LibaryPath%/string:52:0,
                   from %LibaryPath%/bits/locale_classes.h:40,
                   from %LibaryPath%/bits/ios_base.h:41,
                   from %LibaryPath%/ios:42,
                   from %LibaryPath%/istream:38,
                   from test.cpp:2:
  %LibaryPath%/bits/basic_string.h:5167:5: note: candidate: template&lt;class _CharT, class _Traits, class _Alloc&gt; std::basic_ostream&lt;_CharT, _Traits&gt;&amp; std::operator&lt;&lt;(std::basic_ostream&lt;_CharT, _Traits&gt;&amp;, const std::__cxx11::basic_string&lt;_CharT, _Traits, _Alloc&gt;&amp;)
       operator&lt;&lt;(basic_ostream&lt;_CharT, _Traits&gt;&amp; __os,
       ^
  %LibaryPath%/bits/basic_string.h:5167:5: note:   template argument deduction/substitution failed:
  test.cpp:23:18: note:   mismatched types 'std::basic_ostream&lt;_CharT, _Traits&gt;' and 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}'
       buf &lt;&lt; (*this); //!&lt; ERROR HERE
                    ^
  test.cpp:9:26: note: candidate: std::ostream&amp; operator&lt;&lt;(std::ostream&amp;, const Test&amp;)
       friend std::ostream&amp; operator &lt;&lt; (std::ostream&amp; lhs, const Test&amp; rhs) { rhs.onSave(lhs); return lhs; }
                            ^
  test.cpp:9:26: note:   no known conversion for argument 1 from 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}' to 'std::ostream&amp; {aka std::basic_ostream&lt;char&gt;&amp;}'
  test.cpp:24:9: error: no match for 'operator&gt;&gt;' (operand types are 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}' and 'Test')
       buf &gt;&gt; (*tmp);
           ^
  In file included from test.cpp:2:0:
  %LibaryPath%/istream:924:5: note: candidate: template&lt;class _CharT, class _Traits, class _Tp&gt; std::basic_istream&lt;_CharT, _Traits&gt;&amp; std::operator&gt;&gt;(std::basic_istream&lt;_CharT, _Traits&gt;&amp;&amp;, _Tp&amp;)
       operator&gt;&gt;(basic_istream&lt;_CharT, _Traits&gt;&amp;&amp; __is, _Tp&amp; __x)
       ^
  %LibaryPath%/istream:924:5: note:   template argument deduction/substitution failed:
  test.cpp:24:17: note:   mismatched types 'std::basic_istream&lt;_CharT, _Traits&gt;' and 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}'
       buf &gt;&gt; (*tmp);
                   ^
  In file included from test.cpp:2:0:
  %LibaryPath%/istream:808:5: note: candidate: template&lt;class _Traits&gt; std::basic_istream&lt;char, _Traits&gt;&amp; std::operator&gt;&gt;(std::basic_istream&lt;char, _Traits&gt;&amp;, signed char*)
       operator&gt;&gt;(basic_istream&lt;char, _Traits&gt;&amp; __in, signed char* __s)
       ^
  %LibaryPath%/istream:808:5: note:   template argument deduction/substitution failed:
  test.cpp:24:17: note:   mismatched types 'std::basic_istream&lt;char, _Traits&gt;' and 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}'
       buf &gt;&gt; (*tmp);
                   ^
  In file included from test.cpp:2:0:
  %LibaryPath%/istream:803:5: note: candidate: template&lt;class _Traits&gt; std::basic_istream&lt;char, _Traits&gt;&amp; std::operator&gt;&gt;(std::basic_istream&lt;char, _Traits&gt;&amp;, unsigned char*)
       operator&gt;&gt;(basic_istream&lt;char, _Traits&gt;&amp; __in, unsigned char* __s)
       ^
  %LibaryPath%/istream:803:5: note:   template argument deduction/substitution failed:
  test.cpp:24:17: note:   mismatched types 'std::basic_istream&lt;char, _Traits&gt;' and 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}'
       buf &gt;&gt; (*tmp);
                   ^
  In file included from test.cpp:2:0:
  %LibaryPath%/istream:761:5: note: candidate: template&lt;class _Traits&gt; std::basic_istream&lt;char, _Traits&gt;&amp; std::operator&gt;&gt;(std::basic_istream&lt;char, _Traits&gt;&amp;, signed char&amp;)
       operator&gt;&gt;(basic_istream&lt;char, _Traits&gt;&amp; __in, signed char&amp; __c)
       ^
  %LibaryPath%/istream:761:5: note:   template argument deduction/substitution failed:
  test.cpp:24:17: note:   mismatched types 'std::basic_istream&lt;char, _Traits&gt;' and 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}'
       buf &gt;&gt; (*tmp);
                   ^
  In file included from test.cpp:2:0:
  %LibaryPath%/istream:756:5: note: candidate: template&lt;class _Traits&gt; std::basic_istream&lt;char, _Traits&gt;&amp; std::operator&gt;&gt;(std::basic_istream&lt;char, _Traits&gt;&amp;, unsigned char&amp;)
       operator&gt;&gt;(basic_istream&lt;char, _Traits&gt;&amp; __in, unsigned char&amp; __c)
       ^
  %LibaryPath%/istream:756:5: note:   template argument deduction/substitution failed:
  test.cpp:24:17: note:   mismatched types 'std::basic_istream&lt;char, _Traits&gt;' and 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}'
       buf &gt;&gt; (*tmp);
                   ^
  In file included from %LibaryPath%/istream:934:0,
                   from test.cpp:2:
  %LibaryPath%/bits/istream.tcc:923:5: note: candidate: template&lt;class _CharT, class _Traits&gt; std::basic_istream&lt;_CharT, _Traits&gt;&amp; std::operator&gt;&gt;(std::basic_istream&lt;_CharT, _Traits&gt;&amp;, _CharT&amp;)
       operator&gt;&gt;(basic_istream&lt;_CharT, _Traits&gt;&amp; __in, _CharT&amp; __c)
       ^
  %LibaryPath%/bits/istream.tcc:923:5: note:   template argument deduction/substitution failed:
  test.cpp:24:17: note:   mismatched types 'std::basic_istream&lt;_CharT, _Traits&gt;' and 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}'
       buf &gt;&gt; (*tmp);
                   ^
  In file included from %LibaryPath%/istream:934:0,
                   from test.cpp:2:
  %LibaryPath%/bits/istream.tcc:955:5: note: candidate: template&lt;class _CharT2, class _Traits2&gt; std::basic_istream&lt;_CharT, _Traits&gt;&amp; std::operator&gt;&gt;(std::basic_istream&lt;_CharT, _Traits&gt;&amp;, _CharT2*)
       operator&gt;&gt;(basic_istream&lt;_CharT, _Traits&gt;&amp; __in, _CharT* __s)
       ^
  %LibaryPath%/bits/istream.tcc:955:5: note:   template argument deduction/substitution failed:
  test.cpp:24:17: note:   mismatched types 'std::basic_istream&lt;_CharT, _Traits&gt;' and 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}'
       buf &gt;&gt; (*tmp);
                   ^
  In file included from %LibaryPath%/string:53:0,
                   from %LibaryPath%/bits/locale_classes.h:40,
                   from %LibaryPath%/bits/ios_base.h:41,
                   from %LibaryPath%/ios:42,
                   from %LibaryPath%/istream:38,
                   from test.cpp:2:
  %LibaryPath%/bits/basic_string.tcc:1441:5: note: candidate: template&lt;class _CharT, class _Traits, class _Alloc&gt; std::basic_istream&lt;_CharT, _Traits&gt;&amp; std::operator&gt;&gt;(std::basic_istream&lt;_CharT, _Traits&gt;&amp;, std::__cxx11::basic_string&lt;_CharT, _Traits, _Alloc&gt;&amp;)
       operator&gt;&gt;(basic_istream&lt;_CharT, _Traits&gt;&amp; __in,
       ^
  %LibaryPath%/bits/basic_string.tcc:1441:5: note:   template argument deduction/substitution failed:
  test.cpp:24:17: note:   mismatched types 'std::basic_istream&lt;_CharT, _Traits&gt;' and 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}'
       buf &gt;&gt; (*tmp);
                   ^
  test.cpp:8:26: note: candidate: std::istream&amp; operator&gt;&gt;(std::istream&amp;, Test&amp;)
       friend std::istream&amp; operator &gt;&gt; (std::istream&amp; lhs, Test&amp; rhs) { rhs.onLoad(lhs); return lhs; }
                            ^
  test.cpp:8:26: note:   no known conversion for argument 1 from 'std::stringstream&amp;() {aka std::__cxx11::basic_stringstream&lt;char&gt;&amp;()}' to 'std::istream&amp; {aka std::basic_istream&lt;char&gt;&amp;}'
  </code></pre>