title: How to iterate properly across a const set?
body: <p>I'm working on a program that's supposed to represent a graph. My issue is in my printAdjacencyList function. Basically, I have a Graph ADT that has a member variable "nodes", which is a map of the nodes of that graph. Each Node has a set of Edge* to the edges it is connected to. I'm trying to iterate across each node in the graph and each edge of a node.</p>
  
  <pre><code>void MyGraph::printAdjacencyList() {
  std::map&lt;std::string, MyNode*&gt;::iterator mit;
  std::set&lt;MyEdge*&gt;::iterator sit;
  
  for (mit = nodes.begin(); mit != nodes.end(); mit++ ) {
      std::cout &lt;&lt; mit-&gt;first &lt;&lt; ": {";
      const std::set&lt;MyEdge*&gt; edges = mit-&gt;second-&gt;getEdges();
      for (sit = edges.begin(); sit != edges.end(); sit++) {
          std::pair&lt;MyNode*, MyNode*&gt; edgeNodes = *sit-&gt;getEndpoints();
      }
  }
  std::cout &lt;&lt; " }" &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>getEdges is declared as:</p>
  
  <pre><code>const std::set&lt;MyEdge*&gt;&amp; getEdges() { return edges; };
  </code></pre>
  
  <p>and get Endpoints is declared as:</p>
  
  <pre><code>const std::pair&lt;MyNode*, MyNode*&gt;&amp; getEndpoints() { return nodes; };
  </code></pre>
  
  <p>The compiler error I'm getting is:</p>
  
  <pre><code>MyGraph.cpp:63: error: request for member `getEndpoints' in 
  `*(&amp;sit)-&gt;std::_Rb_tree_const_iterator&lt;_Tp&gt;::operator-&gt;
  [with _Tp = MyEdge*]()', which is of non-class type `MyEdge* const'
  
  MyGraph.cpp:63: warning: unused variable 'edgeNodes'
  </code></pre>
  
  <p>I have figured out that this probably means I'm misusing const somewhere, but I can't figure out where for the life of me. Any information would be appreciated. Thanks!</p>