Ambiguous use of operator<< inside my class
<p>I have a problem with creating an operator&lt;&lt; in a class in this particular situation. I have a class that wraps a std::ostream so I can do some preprocessing for some types or some conditions before passing to the ostream, and want to pass some things straight through. I don't want to inherit the std::ostream, unless there is a good argument that I should. (I think I tried it once and found great difficulty and no success.)</p>

<p>I cannot use a template function because the processing depends on type in some cases, and I think the ambiguity would remain between it and those for my specific types (like 'Stuff'). Do I have to resort to using typeid ??</p>

<pre><code>class MyClass
{
  private:
    std::ostream &amp; m_out;

  public:
    MyClass (std::ostream &amp; out)
      : m_out(out)
    {}

    MyClass &amp; operator&lt;&lt; (const Stuff &amp; stuff)
    {
        //...
        // something derived from processing stuff, unknown to stuff
        m_out &lt;&lt; something;
        return *this;
    }

    // if I explicitly create operator&lt;&lt; for char, int, and double, 
    // such as shown for char and int below, I get a compile error: 
    // ambiguous overload for 'operator&lt;&lt;' on later attempt to use them.

    MyClass &amp; operator&lt;&lt; (char c)
    {
        m_out &lt;&lt; c; // needs to be as a char
        return *this;
    }

    MyClass &amp; operator&lt;&lt; (int i)
    {
        if (/* some condition */)
            i *= 3;
        m_out &lt;&lt; i; // needs to be as an integer
        return *this;
    }

    // ...and other overloads that do not create an ambiguity issue...
    // MyClass &amp; operator&lt;&lt; (const std::string &amp; str)
    // MyClass &amp; operator&lt;&lt; (const char * str)        
};

void doSomething ()
{
    MyClass proc(std::cout);
    Stuff s1, s2;
    unsigned i = 1;
    proc &lt;&lt; s1 &lt;&lt; "using stuff and strings is fine" &lt;&lt; s2;
    proc &lt;&lt; i; // compile error here: ambiguous overload for 'operator&lt;&lt;' in 'proc &lt;&lt; i'
}
</code></pre>
