title: A simple Linked List implementation in C++
body: <p>I am trying to implement a simple linked list using c++. I am probably making a silly mistake somewhere.Through this i want to learn classes and pointers in C++.
  For the code</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class node
  {
  public: 
      node* next;
      int data;
  
      node(int d);
      void append(int d);
  }; 
  
  node::node(int d)
  {
      data = d;
      next = NULL;
  }
  
  
  void node::append(int d)
  {
      node nw = node(d);
      if(next==NULL)
          next = &amp;nw;
      else
      {
          node *n = next;
          while((*n).next!=NULL)
          {
              n = (*n).next;
          }
          (*n).next = &amp;nw;
      }
  }
  </code></pre>
  
  <p>I am getting 81 as the node next to 1.</p>
  
  <pre><code>int main()
  {
      node n = node(1);
      n.append(3);
      n.append(2);
      n.append(81);
      n = *(n.next);
      cout&lt;&lt; n.data &lt;&lt; '\n';
  }
  </code></pre>
  
  <p>Please help me figure out where am i making mistake. </p>