title: Getter worked but returns an error when i turn it into a const
body: <p>So I'm currently developping a so and a dll file to handle the files of my users (basically a filesystem).
  I have two classes, one is <em>FileData</em> (representing a single file), and a <em>FileList</em> (which as the name suggests is a list of FileDatas). Here is my problem. My <strong>code was working</strong>, but I needed to implement a sort method based on the metadatas I get on my file and to do that I needed to get my getter to a <strong>const method</strong> :</p>
  
  <p>I'm compiling with the flags <strong>-Wextra -Wall -Werror</strong> </p>
  
  <p><strong>FileData.hpp</strong></p>
  
  <pre><code>class FileData
  {
   // ...
   std::vector&lt;std::pair&lt;std::string, std::string&gt; &gt; _metadatas;
  public:
   FileData(std::string);
   ~FileData();
   FileData(const FileData &amp;);
   std::vector&lt;std::pair&lt;std::string, std::string&gt; &gt; &amp;getMetadatas() const;
  };
  </code></pre>
  
  <p><strong>FileData.cpp</strong> (i tried to both return (_metadatas) and (&amp;_metadatas) both fail)</p>
  
  <pre><code>std::vector&lt;std::pair&lt;std::string, std::string&gt; &gt; &amp;FileData::getMetadatas() const
   {
     return (_metadatas);
   }
  </code></pre>
  
  <p>And here is the <strong>error message</strong> :</p>
  
  <pre><code> FileData.cpp: In member function ‘std::vector&lt;std::pair&lt;std::basic_string&lt;char&gt;, std::basic_string&lt;char&gt; &gt; &gt;&amp; FileData::getMetadatas() const’:
   FileData.cpp:164:23: error: invalid initialization of reference of type ‘std::vector&lt;std::pair&lt;std::basic_string&lt;char&gt;, std::basic_string&lt;char&gt; &gt; &gt;&amp;’ from expression of type ‘const std::vector&lt;std::pair&lt;std::basic_string&lt;char&gt;, std::basic_string&lt;char&gt; &gt; &gt;’
   return (_metadatas);
                      ^
  make: *** [FileData.o] Error 1
  </code></pre>
  
  <p>And here is the reason in my FileList.cpp i need to get the getMetadatas a const getter (even though i know getters should always be const anyway) :</p>
  
  <p><strong>FileList.cpp</strong></p>
  
  <pre><code>bool                SortMetadata::sortArtist(const FileData &amp;a, const FileData &amp;b)
  {
     int i,j;
     std::vector&lt;std::pair&lt;std::string, std::string&gt; &gt; tmp, temp;
     tmp = a.getMetadatas();
     temp = b.getMetadatas();
     std::string first("");
     std::string second("");
     for (i = 0; i &lt; tmp.size(); ++i)
      {
         if (tmp[i].first.compare("artist") == 0)
             first = tmp[i].second;
      }
     for (j = 0; j &lt; temp.size(); ++j)
      {
          if (temp[j].first.compare("artist") == 0)
              second = temp[j].second;
      }
     return (first.compare(second) &lt; 0);
  }
  </code></pre>
  
  <p>Here is the <strong>error message</strong> i get if i don't make my getMetadatas() a const method : </p>
  
  <pre><code> FileList.cpp: In function ‘bool SortMetadata::sortArtist(const FileData&amp;, const FileData&amp;)’:
   FileList.cpp:91:26: error: passing ‘const FileData’ as ‘this’ argument of ‘std::vector&lt;std::pair&lt;std::basic_string&lt;char&gt;, std::basic_string&lt;char&gt; &gt; &gt;&amp;  FileData::getMetadatas()’ discards qualifiers [-fpermissive]
   tmp = a.getMetadatas();
                        ^
   FileList.cpp:92:27: error: passing ‘const FileData’ as ‘this’ argument of ‘std::vector&lt;std::pair&lt;std::basic_string&lt;char&gt;, std::basic_string&lt;char&gt; &gt; &gt;&amp; FileData::getMetadatas()’ discards qualifiers [-fpermissive]
   temp = b.getMetadatas();
  </code></pre>
  
  <p>I'm not sure what's the problem here, since the code was working fine before I changed my getter to const, and I don't understand what it changes to be const, since the method is just a return..
  <strong>Thanks for the help guys !</strong></p>