title: C++ Recursive Print Function for IntStack
body: <p>I've been tasked with creating a print function that uses recursion to print the data of a singly linked list (stack). Here is my code thus far:
  <br /><br />IntStack.h
  </p>
  
  <pre><code>#include &lt;iostream&gt;
  
  struct NodeType
  {
      int data;
      NodeType *next;
  };
  
  class IntStack
  {
  private:
      NodeType root;
      int count;
  public:
      IntStack(void);
      ~IntStack(void);
  
      void push(int);
      int pop(void);
      bool isEmpty(void);
      void print(NodeType&amp;);
      int getSize() const;
      NodeType* getRoot();
  };
  </code></pre>
  
  <p>IntStack.cpp
  </p>
  
  <pre><code>#include "IntStack.h"
  
  IntStack::IntStack()
  {
      count = 0;
  }
  
  IntStack::~IntStack()
  {
  
  }
  
  void IntStack::push(int num)
  {
      NodeType newNode;
      newNode.data = num;
  
      newNode.next = &amp;root;
      root = newNode;
  
      ++count;
  }
  
  int IntStack::pop(void)
  {
      // get root data
      // set root equal to root.next
      int num = root.data;
      root = *root.next;
      --count;
      return num;
  }
  
  bool IntStack::isEmpty(void)
  {
      return (count == 0);
  }
  
  void print(NodeType *node)
  {
      if (node-&gt;next != NULL) {
          std::cout &lt;&lt; node-&gt;data &lt;&lt; " " &lt;&lt; std::endl;
          print(node-&gt;next);
      }
  }
  
  NodeType* IntStack::getRoot()
  {
      return &amp;root;
  }
  
  int IntStack::getSize() const
  {
      return count;
  }
  </code></pre>
  
  <p>main.cpp
  </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "IntStack.h"
  
  int main()
  {
      IntStack stack;
      stack.push(7);
      stack.push(10);
      stack.push(13);
      stack.push(43);
      stack.push(23);
      stack.push(5);
      stack.push(32);
      stack.push(8);
  
      std::cout &lt;&lt; stack.getSize() &lt;&lt; " item(s) in the stack." &lt;&lt; std::endl;
      std::cout &lt;&lt; "Pop item off stack: " &lt;&lt; stack.pop() &lt;&lt; std::endl;
      std::cout &lt;&lt; stack.getSize() &lt;&lt; " item(s) in the stack." &lt;&lt; std::endl;
  
      stack.print(stack.getRoot());
  
      return 0;
  }
  </code></pre>
  
  <p>I'm receiving an error on the stack.print(stack.getRoot()) function in main.cpp:</p>
  
  <blockquote>
    <p>main.cpp:28:17: Non-const lvalue reference to type 'NodeType' cannot bind to a temporary of type 'NodeType *'</p>
  </blockquote>
  
  <p>Obviously, I'm not sending a pointer to the function, but I've tried various ways to send the root node with no luck. Any information on how I should proceed is greatly appreciated. Thanks</p>