title: How to return Pointer to a object from List of objects using iterators
body: <p>When I traverse a list of objects and I have to return the pointer to one of my object when I have a iterator pointing to it, how I do so ? In short can one tell what should I put in the place of  ???</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;list&gt;
  
  using namespace std;
  
  class Node
  {
  private:
      int name;
  public:
      Node() : name(0) {}
      Node(int n) : name(n) {}
      int getName() {return name;}
      void setName(int n) {name = n;}
  };
  
  list&lt;Node&gt; mylist;
  
  Node* getNodeObjectPointer(int n)
  {
      Node* toBeReturned = NULL;
      for(list&lt;Node&gt;::iterator it=mylist.begin(); it != mylist.end(); it++)
      {
          if(((*it).getName()) == n)
              toBeReturned = ???
      }
      return toBeReturned;
  } 
  
  int main()
  {
      Node* a = new Node(1);
      mylist.push_back(*a);
      Node* b = new Node(2);
      mylist.push_back(*b);
  
      Node* myPointer = getNodeObjectPointer(1);
      return 0;
  }
  </code></pre>