title: Needing a private and public method for the same recursive function
body: <p>We have recently been working on implementing recursive methods for several classes (trees, heaps, queues, linked lists, etc) in C++ for my computer science class. I have not been having any trouble writing the implementations for the methods, but something my professor mentioned briefly in passing confused me and she never elaborated on the point.</p>
  
  <p>She mentioned that when implementing a recursive function for a class you need to have both a public and private version of that function.</p>
  
  <p>For example (part of a linked list class definition): </p>
  
  <pre><code>public: 
    // constructors, destructors
    // member functions etc.
    findMax() { findMax(head); }
  private:
    findMax(Node* first_node) { // actual code with recursive calls }
    Node* head;
  </code></pre>
  
  <p>So here there are two functions, one private and one public. All the public function does is call the private function and return whatever it finds to be the answer.</p>
  
  <p>I have a few questions about this.</p>
  
  <p>Is this something you must do?
  Does this only apply to class methods that are recursive? If so, what about recursive functions makes this necessary? Would you do this for other functions?</p>
  
  <p>My intuition is that perhaps this is done to ensure that people using the public class methods don't go full dingus mode and end up calling a recursive function with parameters that won't ever lead to a stopping/base case.</p>
  
  <p>Can anyone elaborate on this idea in general and explain it in an intuitive way?</p>
  
  <p>Thanks!</p>
  
  <p>EDIT: Thank you all for your quick answers they have been very helpful! I think I may have misheard my professor and this actually has nothing to do with recursion (though the example she was writing may have been) and is rather just a convention in Object Oriented Programming. </p>
  
  <p>The idea within OOP being that findMax() requires the use of a private class variable (head) to be of use, but would be a handy public function. The private version of findMax(Node* n) then allows a public user to find the max of the list without having the opportunity to access and mess up the private head.</p>
  
  <p>Thanks everyone! Cheers.</p>