Overloading output (<<) operator for a class with private enum member
<p>I'm having a hard time trying to overload my &lt;&lt; output operator for this class. The class has private members - <code>enum class</code> and <code>string</code>. The code I made compiles and runs, but the &lt;&lt; operator is overloaded only for the enum class.
From what I understand and read about it, I need to make something like this:</p>

<blockquote>
  <p>friend ostream&amp; operator&lt;&lt;(ostream&amp; os, CDirectory const&amp; dir)</p>
</blockquote>

<p>but I seem to fail at implementing it and at this point I really have no ideas. I want to overload the operator for the whole <code>class CDirectory</code> and not only the <code>enum class Filetype</code>, that is one of the members. Is this even possible to do?</p>

<pre><code>class CDirectory {
    string m_strDirectory;
    enum class Filetype {
        Archive, Hidden, ReadOnly, System, FileNotSupported
    };
    multimap &lt;CFile, Filetype&gt; m_DirectoryMap;
public:
    /* overloading operator&lt;&lt; for the enum class Filetype */
    friend ostream&amp; operator&lt;&lt;(ostream&amp; os, Filetype const type)
    {
        switch (type)
        {
        case Filetype::Archive:
            os &lt;&lt; "archive";
            break;
        case Filetype::Hidden:
            os &lt;&lt; "hidden";
            break;
        case Filetype::ReadOnly:
            os &lt;&lt; "read-only";
            break;
        case Filetype::System:
            os &lt;&lt; "system";
            break;
        case Filetype::FileNotSupported:
            os &lt;&lt; "not-supported";
            break;
        }
        return os;
    }
    /* explicit constructor - reads data from a file and inserts pairs
      of types pair &lt;CFile, enum Filetype&gt; in a multimap */
    CDirectory (const string&amp; n) {
        fp.open (n, ios::in);
        string dirName, fileName,  fType;
        int fileSize;
        Filetype filetype;
        fp &gt;&gt; dirName;
        m_strDirectory = dirName;
        while (fp &gt;&gt; fileName &gt;&gt; fileSize &gt;&gt; fType) {
            CFile obj (fileName, fileSize);
            if (fType == "Archive")
                filetype = Filetype::Archive;
            else if (fType == "Hidden")
                filetype = Filetype::Hidden;
            else if (fType == "ReadOnly")
                filetype = Filetype::ReadOnly;
            else if (fType == "System")
                filetype = Filetype::System;
            else
                filetype = Filetype::FileNotSupported;
            m_DirectoryMap.insert(pair&lt;CFile, Filetype&gt;(CFile(obj.getFileName(), obj.getFileSize()), Filetype(filetype)));
        }
        auto p = m_DirectoryMap.begin();
        cout &lt;&lt; m_strDirectory &lt;&lt; endl;
        while ( p != m_DirectoryMap.end()) {
            cout &lt;&lt; endl &lt;&lt; p-&gt;first.getFileName() &lt;&lt; '\t' &lt;&lt; p-&gt;first.getFileSize() &lt;&lt; '\t' &lt;&lt; p-&gt;second &lt;&lt; endl;
            ++p;
        }
    }
    void printMap () {
         auto p = m_DirectoryMap.begin();
         cout &lt;&lt; m_strDirectory &lt;&lt; endl;
         while ( p != m_DirectoryMap.end()) {
                cout &lt;&lt; endl &lt;&lt; p-&gt;first.getFileName() &lt;&lt; '\t' &lt;&lt; p-&gt;first.getFileSize() &lt;&lt; '\t' &lt;&lt; p-&gt;second &lt;&lt; endl;
                ++p;
        }
    }
};
</code></pre>

<p><strong>UPDATE:</strong></p>

<p>I tried the following code, for implementing the overload operator &lt;&lt; for my entire class, but it produces an error - <code>error: cannot bind 'std::basic_ostream&lt;char&gt;' lvalue to 'std::basic_ostream&lt;char&gt;&amp;&amp;'|</code>on these lines (1 of them is in my constructor and 1 in my printMap function) -  <code>cout &lt;&lt; endl &lt;&lt; p-&gt;first.getFileName() &lt;&lt; '\t' &lt;&lt; p-&gt;first.getFileSize() &lt;&lt; '\t' &lt;&lt; p-</code>>second &lt;&lt; endl; 
I'm guessing that it has something to do with the <code>p-&gt;second</code> part, but I don't know what exactly is going on. Any thoughts on it?</p>

<p>Update: yep, the problem is when I try to print out the enum with <code>p-&gt;second</code>. If I remove that part it compiles..</p>

<pre><code>std::ostream&amp; operator&lt;&lt;(std::ostream &amp;os, const CDirectory &amp;dir)
    {
        const Filetype&amp; type;
        switch (type)
        {
        case Filetype::Archive:
            os &lt;&lt; "archive";
            break;
        case Filetype::Hidden:
            os &lt;&lt; "hidden";
            break;
        case Filetype::ReadOnly:
            os &lt;&lt; "read-only";
            break;
        case Filetype::System:
            os &lt;&lt; "system";
            break;
        case Filetype::FileNotSupported:
            os &lt;&lt; "not-supported";
            break;
        }
        os &lt;&lt; dir.m_strDirectory &lt;&lt; "\n";
        for(auto &amp;p : dir.m_DirectoryMap) {
           os &lt;&lt; p.first.getFileName() &lt;&lt; '\t' &lt;&lt; p.first.getFileSize() &lt;&lt; '\t' &lt;&lt; p.second &lt;&lt; '\n';
        }
        return os;
    }
</code></pre>