title: C++ : How to return the value the iterator of a set is pointing to?
body: <p>My return value from an iterator over a set gives the memory location instead of the value. How do I access the element the iterator is pointing to?</p>
  
  <p>I used a similar iterator loop before which worked fine, as in returning the value the iterator is pointing to (for both a deque and vector template class).</p>
  
  <p>This question is a follow up on a script I had difficulties with earlier today (<a href="https://stackoverflow.com/questions/36956495/c-adding-an-object-to-a-set">C++ : adding an object to a set</a>).</p>
  
  <p>The script now looks as follows:</p>
  
  <p>header file</p>
  
  <pre><code>#ifndef EMPLOYEE_HH
  #define EMPLOYEE_HH
  
  #include &lt;set&gt;
  #include &lt;string&gt;
  #include &lt;iostream&gt;
  
  using namespace std ;
  
  class Employee {
  
  public:
    // Constructor
    Employee(const char* name, double salary) :
      _name(name),
      _salary(salary) {
    }
  
    // Accessors
    const char* name() const { 
      return _name.c_str() ;
    }
  
    double salary() const {
      return _salary ;
    }
  
    // Print functions
    void businessCard(ostream&amp; os = cout) const {
      os &lt;&lt; "   +--------------------+  " &lt;&lt; endl
         &lt;&lt; "   |  ACME Corporation  |  " &lt;&lt; endl 
         &lt;&lt; "   +--------------------+  " &lt;&lt; endl
         &lt;&lt; "   Name: " &lt;&lt; name() &lt;&lt; endl
         &lt;&lt; "   Salary: " &lt;&lt; salary() &lt;&lt; endl ;
    }
  
  private:
    string _name ;
    double _salary ;
  
  } ;
  
  class Manager : public Employee {
  
  public:
    //Constructor
    Manager(const char* _name, double _salary):
      Employee(_name, _salary),
      _subordinates() {
    }
  
    // Accessors &amp; modifiers
    void addSubordinate(Employee&amp; empl) {
      _subordinates.insert(&amp;empl);
    }
  
    const set&lt;Employee*&gt;&amp; listOfSubordinates() const {
      return _subordinates;
    }
  
    void businessCard(ostream&amp; os = cout) const {
      Employee::businessCard() ;
      os &lt;&lt; "   Function: Manager" &lt;&lt; endl ;
  
      set&lt;Employee*&gt;::iterator iter ;
      iter = _subordinates.begin() ;
  
      os &lt;&lt; "   Subordinates:" &lt;&lt; endl ;
      if(_subordinates.empty()==true) {
        os &lt;&lt; "      Nobody" &lt;&lt; endl;
      }
      while(iter!=_subordinates.end()) {
        os &lt;&lt; "      " &lt;&lt; *iter &lt;&lt; endl ;  // &lt;-- returns the memory location 
        ++iter ;
      }
  
    }
  
  private:
    set&lt;Employee*&gt; _subordinates ;
  } ;
  
  #endif
  </code></pre>
  
  <p>Main script</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;iostream&gt;
  #include "Employee.hh"
  
  using namespace std ;
  
  int main() {
  
     Employee emp1("David", 10000) ;
     Employee emp2("Ivo", 9000) ;
     Manager mgr1("Oscar", 18000) ;   // Manager of Ivo and David
     Manager mgr2("Jo", 14000) ;
     Manager mgr3("Frank", 22000) ;  // Manager of Jo and Oscar (and Ivo and David)
  
     mgr1.addSubordinate(emp1) ;
     mgr1.addSubordinate(emp2) ;
     mgr3.addSubordinate(mgr1) ;
     mgr3.addSubordinate(mgr2) ;
  
     cout &lt;&lt; '\n' ;
     emp1.businessCard() ;
  
     cout &lt;&lt; '\n' ;
     emp2.businessCard() ;
  
     cout &lt;&lt; '\n' ;
     mgr1.businessCard() ;
  
     cout &lt;&lt; '\n' ;
     mgr2.businessCard() ;
  
     cout &lt;&lt; '\n' ;
     mgr3.businessCard() ;
  
     cout &lt;&lt; '\n' ;       
     return 0;
  }
  </code></pre>
  
  <p>Any help is much appreciated. </p>