C++ friend operator overload doesn't compile
<p>I have the following (cut-down) class definition, and it has compilation errors.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
class number
{
    public:
        friend std::ostream &amp;operator &lt;&lt; (std::ostream &amp;s, const number &amp;num);
        friend std::string  &amp;operator &lt;&lt; (std::string,     const number &amp;num);
        friend std::istream &amp;operator &gt;&gt; (std::istream &amp;s,       number &amp;num);
        friend std::string  &amp;operator &gt;&gt; (std::string,           number &amp;num);
    protected:
    private:
        void write (      std::ostream &amp;output_target = std::cout) const;
        void read  (      std::istream &amp;input_source  = std::cin);
        void to_string (      std::string &amp;number_text) const;
        void to_number (const std::string &amp;number_text);
};

std::istream &amp; operator &gt;&gt; (std::istream &amp;s,       number &amp;num)
{
    num.read (s);
    return s;
}
std::string  &amp; operator &gt;&gt; (std::string &amp;s, number &amp;num)
{
    num.to_number (s);
    return s;
}
std::string  &amp; operator &lt;&lt; (std::string &amp;s, const number &amp;num)
{
    num.to_string (s);
    return s;
}
std::ostream &amp; operator &lt;&lt; (std::ostream &amp;s, const number &amp;num)
{
    num.write (s);
    return s;
}
</code></pre>

<p>When I compile it, I get the following errors...</p>

<pre><code>frag.cpp: In function ‘std::string&amp; operator&gt;&gt;(std::string&amp;, number&amp;)’:
frag.cpp:17: error: ‘void number::to_number(const std::string&amp;)’ is private
frag.cpp:27: error: within this context
frag.cpp: In function ‘std::string&amp; operator&lt;&lt;(std::string&amp;, const number&amp;)’:
frag.cpp:16: error: ‘void number::to_string(std::string&amp;) const’ is private
frag.cpp:32: error: within this context
</code></pre>

<p>Could anyone help with this; in particular why to_number and to_string are thought private but read and write are OK?</p>

<p>Thank you.</p>
