title: Pointers within class methods
body: <p>How do I make a pointer within a method of a class point to the object that the method is being called on?</p>
  
  <p>I want to define a pointer in the body of a public method of a class and have it point to the instance of the object that the method is being called on.</p>
  
  <p>Here's my code for some more context:</p>
  
  <pre><code>void Node::print() {
      Node *temp = this; //points to the node that calls the print function
  
      while (temp-&gt;next != NULL) {
          cout &lt;&lt; "Name:  " &lt;&lt; temp-&gt;name &lt;&lt; "\tID:  " &lt;&lt; temp-&gt;ID &lt;&lt; endl;
          temp = temp-&gt;next; //makes temp-&gt;next point to the next node in the list.
      }
  
      //this line runs when temp-&gt;next == NULL
      cout &lt;&lt; "Name:  " &lt;&lt; temp-&gt;name &lt;&lt; "\tID:  " &lt;&lt; temp-&gt;ID &lt;&lt; endl;
  }
  </code></pre>