title: Why is this pop() function creating a seg fault?
body: <p>I have the class <code>stackLL</code> and the <code>pop()</code> function creates a seg fault when used in the main. Here's the code:</p>
  
  <p>Here's the struct and class definitions:</p>
  
  <pre><code>struct llNode{
  int data;
  llNode* next;
  };
  
  class stackLL{
  public:
  stackLL();
  void push(int x);
  int pop();
  void print();
  
  private:
  llNode* head;
  };
  </code></pre>
  
  <p>Here's the member function definition:</p>
  
  <pre><code>int stackLL::pop(){
      if (head == NULL){
      return false;
      }
  
      else {
      llNode *tmp= new llNode;
      cout&lt;&lt;"The integer is: "&lt;&lt;head -&gt; data;
      tmp = head;
      head = tmp -&gt; next;
      delete tmp;
      return tmp -&gt; data;
  
      }
  }
  </code></pre>
  
  <p>Here's the implementation in main:</p>
  
  <pre><code>stackLL sll;
  </code></pre>
  
  <p><em>couple lines down</em></p>
  
  <pre><code> sll.pop();
  </code></pre>