title: When using map::erase() "error: passing 'const ***' as 'this' argument of '***' discards qualifiers [-fpermissive]" reported
body: <p>I'm implementing the following method to delete an element from an associative table (<code>map</code>) with <code>map::erase()</code>:</p>
  
  <pre><code>//Method in gestion.cpp
  void Gestion::EliminateObject(string nomobjetg) const{
  
      auto it = objectname.find(nameobjectg);
  
      if (it == objectname.end())
          cout &lt;&lt; "Object not found!" &lt;&lt; endl;
      else
          objectname.erase(it); //The error is reported in this line
  }
  </code></pre>
  
  <p>In the header I have defined the following:</p>
  
  <pre><code>//gestion.h
  #include "objects.h"
  #include &lt;list&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;memory&gt;
  #include &lt;map&gt;
  using namespace std;
  
  typedef std::shared_ptr&lt;Objects&gt; ObjPtr;
  
  typedef map&lt;string, ObjPtr&gt; Objectmap;
  
  class Gestion
  {
  private:
       Objectmap objectname;
  
  public:
      Gestion(Objectmap objectname, Groupmap groupname);
      virtual ~Gestion() {}
      virtual void EliminateObject(string nameobjectg) const;
  };
  </code></pre>
  
  <p>Where <code>ObjPtr</code> is a virtual pointer of objects of type <code>Objects</code>.</p>
  
  <p>When I compile I get this error:</p>
  
  <pre><code>error: passing ‘const Objectmap {aka const std::map&lt;std::basic_string&lt;char&gt;, std::shared_ptr&lt;Objects&gt; &gt;}’ as ‘this’ argument of ‘std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::iterator std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::erase(std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::const_iterator) [with _Key = std::basic_string&lt;char&gt;; _Tp = std::shared_ptr&lt;Objects&gt;; _Compare = std::less&lt;std::basic_string&lt;char&gt; &gt;; _Alloc = std::allocator&lt;std::pair&lt;const std::basic_string&lt;char&gt;, std::shared_ptr&lt;Objects&gt; &gt; &gt;; std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::iterator = std::_Rb_tree_iterator&lt;std::pair&lt;const std::basic_string&lt;char&gt;, std::shared_ptr&lt;Objects&gt; &gt; &gt;; std::map&lt;_Key, _Tp, _Compare, _Alloc&gt;::const_iterator = std::_Rb_tree_const_iterator&lt;std::pair&lt;const std::basic_string&lt;char&gt;, std::shared_ptr&lt;Objects&gt; &gt; &gt;]’ discards qualifiers [-fpermissive]
           objectname.erase(it);
  </code></pre>
  
  <p>Why is this line reporting this error? I've seen some other posts with this type of error but in those cases the root cause of the problem is related to how the method is declared (<code>const</code>). In this case the method involved in the problem is <code>erase</code> and I cannot modify it.</p>