title: strange errors in map in C++
body: <p>Compiler says<br />
  <strong>ERROR1: the object has type qualifiers that are not compatible with the member function &quot;NAME::getName&quot; object type is : const NAME</strong></p>
  <p><strong>ERROR2: 'std::string NAME::getName(void)': cannot convert 'this' pointer from '_Ty1' to 'NAME &amp;'</strong></p>
  <p>on <code>cout &lt;&lt; (it-&gt;first).getName();</code></p>
  <p>So why is that and how to make it work?</p>
  <pre><code>#include &lt;map&gt;
  #include &lt;iostream&gt;
  using namespace std;
  
  class NAME
  {
  private:
      string name;
  
  public:
      NAME(string name)
      {
          this-&gt;name = name;
      }
  
      string getName()
      {
          return name;
      }
  };
  
  int main()
  {
      map &lt;NAME, int&gt; telephoneBook = { {NAME(&quot;Alex&quot;), 1122},
                                        {NAME(&quot;Oleg&quot;), 3344} };
  
      for (auto it = telephoneBook.begin(); it != telephoneBook.end(); ++it)///вывод на экран
      {
          cout &lt;&lt; (it-&gt;first).getName(); // error 1 and error2
      }
  }
  </code></pre>