No match for 'operator <<' in std::operator << [With _Traits = std::char_traits<char> ]
<p>I have a class Foobar with string conversion operator:</p>

<pre><code>#include &lt;string&gt;

class Foobar
{
public:
   Foobar();
   Foobar(const Foobar&amp;);
   ~Foobar();

   operator std::string() const;
};
</code></pre>

<p>I attempt to use it like this:</p>

<p>//C++ source file</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;sstream&gt;
#include "Foobar.hpp"

int main()
{
   Foobar fb;
   std::stringstream ss;

   ss &lt;&lt; "Foobar is: " &lt;&lt; fb;  // Error occurs here

   std::cout &lt;&lt; ss.str();
}
</code></pre>

<p>Do I need to explicitly create an operator &lt;&lt; for Foobar?. I don't see why that should be necessary since FooBar is converted to a string before being placed in the iostream, and std::string already has operator &lt;&lt; defined.</p>

<p>So why this error?. What am I missing?</p>

<p>[Edit]</p>

<p>I just found out that if I changed the line the error occurs on, to this:</p>

<pre><code>   ss &lt;&lt; "Foobar is: " &lt;&lt; fb.operator  std::string();  
</code></pre>

<p>It compiles successfully. Urgh ...! Why can't the compiler do the automatic conversion (Foobar -> string) ?</p>

<p>What is the 'best practise' way to resolve this, so I don't have to use the ugly syntax above?</p>
