title: overloading operators error: no matching function
body: <p>I have this overloaded operator in my FileDir.cpp implementation file:  </p>
  
  <pre><code> std::ostream&amp; operator&lt;&lt; (std::ostream &amp;out, const FileDir &amp;obj) {
          out &lt;&lt; obj.toString();
          return out;
   }
  </code></pre>
  
  <p>This is my toString() function:</p>
  
  <pre><code>string FileDir::toString()
  
  {
      std::string whatever;
      std::stringstream converter;
      converter &lt;&lt; size;
      converter &gt;&gt; whatever;
  
      std::string combined;
      if (type == false) { 
          combined = name + " " + whatever + "kb";
      }
      if (type == true) {
          combined = name + "/" + " " + whatever + "kb";
      }
      return combined;
  }
  </code></pre>
  
  <p>Here is the error I get:</p>
  
  <pre><code>FileDir.cpp: In function ‘std::ostream&amp; operator&lt;&lt;(std::ostream&amp;, const FileDir&amp;)’:
  FileDir.cpp:125:25: error: no matching function for call to ‘FileDir::toString() const’
       out &lt;&lt; obj.toString();
                           ^
  FileDir.cpp:125:25: note: candidate is:
  FileDir.cpp:84:8: note: std::string FileDir::toString() &lt;near match&gt;
   string FileDir::toString()
          ^
  FileDir.cpp:84:8: note:   no known conversion for implicit ‘this’ parameter from ‘const FileDir*’ to ‘FileDir*’
  </code></pre>
  
  <p>This is my FileDir.h header file:</p>
  
  <pre><code>#include &lt;sstream&gt; 
  
  class FileDir {
  public:
      FileDir();
      FileDir(std::string nameVal, long sizeVal = 4, bool typeVal = false);
      FileDir(const FileDir &amp;obj);
      ~FileDir();            // destructor
      long getSize() const;
      std::string getName() const;
      bool isFile() const;
      std::string rename(std::string newname); 
      long resize(long newsize);
      std::string toString();
      bool operator== (const FileDir &amp;dir1);
      bool operator&lt;(const FileDir &amp;obj);    
  
  private:
      std::string name;
      long size;
      bool type;
  
  };
  </code></pre>
  
  <p>I think there's a problem with my toString() declaration, but I'm not sure.</p>
  
  <p>How do I fix the error?</p>