title: returning something from a linked list
body: <p>Can anybody tell me why my main program is printing out 9460301 instead of 350?
  I'm just trying to insert a struct as a single item into a linked list. The struct has atrributes x and y. I then wish to print out the x attribute of the struct in my linked list. I have a huge program written out, and I tried stripping it down on this post just to what's neccessary to view for this new issue that has arisen for me.</p>
  
  <p>My chunk struct and Linkedlist class are as follows:</p>
  
  <pre><code>struct chunk{
      int x;
      int y;
  };
  
  template &lt;class T&gt;
  class linkedList
  {
  public:
      class node
      {
      public:
          ///node class attributes
          T mPayload;
          node* mNext;
          ///constructor
          node(T toucan):mPayload(toucan),mNext(NULL)
          {}
          ///destructor
          ~node()
          {
              ///cascading delete
              if(mNext)
                  delete mNext;
          }
          ///node class methods
      };
  
      ///linkedList class attributes
      node* mStart;
      ///constructor
      linkedList():mStart(NULL)
      {}
      ///destructor
      ~linkedList()
      {
          ///initializes the cascading delete.
          if(mStart)
              delete mStart;
      }
      ///linkedList class methods
      T mReturnT(int indx)
      {
          if(!mStart)
          {
              T emptyList;
              return emptyList;
          }
          else
          {
              node* cur;
              for(int i = 0; i&lt;indx+1; i++)
              {
                  if(cur-&gt;mNext == NULL)
                  {
                      cout &lt;&lt; "Indx out of range. Deleting last item." &lt;&lt; endl;
                      break;
                  }
                  cur = cur-&gt;mNext;
              }
              return cur-&gt;mPayload;
          }
      }
  
      void mInsertHelper(node* blah, T data)
      {
          if(blah-&gt;mNext != NULL)
              mInsertHelper(blah-&gt;mNext, data);
          else
          {
              blah-&gt;mNext = new node(data);
              blah-&gt;mNext-&gt;mNext = NULL;
          }
      }
  
      void mInsert(T data)
      {
          if(mStart == NULL)
          {
              mStart = new node(data);
              //mStart-&gt;mPayload = data;
          }
          else
              mInsertHelper(mStart, data);
      }
  
      T mPop()
      {
          ///Removes the last item in the list,
          ///and returns it.
          if(!mStart)
              return NULL;
          else
          {
              node* cur = mStart;
              while(cur-&gt;mNext)
              {
                  cur = cur-&gt;mNext;
              }
              T var = cur-&gt;mPayload;
              delete cur;
              return var;
          }
      }
  
      int mSize()
      {
          if(!mStart)
              return 0;
          else
          {
              node* cur = mStart;
              int counter = 1;
              while(cur-&gt;mNext)
              {
                  cur = cur-&gt;mNext;
                  counter++;
              }
              delete cur;
              return counter;
          }
      }
  
  };
  </code></pre>
  
  <p>And my main.cpp:</p>
  
  <pre><code>int main()
  {
      chunk head;
      head.x = 350;
      head.y = 600;
      linkedList&lt;chunk&gt; p1Snake;
      p1Snake.mInsert(head);
  
      cout&lt;&lt;p1Snake.mReturnT(0).x&lt;&lt;endl;
  }
  </code></pre>