title: Debug error overloading a "+" for a template?
body: <p>I've attempted to overload the "+" operator for template. Yet I get a debug  error <code>abort() has been called</code>. The "+" operator should add an item to the end of the list, then return the result. </p>
  
  <p>So if I'm right, let's assume <code>list1</code> has integer items of {4,2,1}. I am guessing writing <code>myList&lt;int&gt; list2 = list1 + 5</code> should make list2 contain the items {4,2,1,5}</p>
  
  <pre><code>template &lt;class type&gt;
  class myList
  {
  protected:
      int length;         //the number of elements in the list
      type *items;        //dynamic array to store the elements
  
  public:
      myList();
  
      //adds one element to a list
      friend myList&amp; operator+ (myList&lt;type&gt; &amp;lhs, const type&amp; t) 
      {
          myList&lt;type&gt; result;
          if (lhs.items == NULL)
          {
              result.items = new type[1];
              result.items[0] = t;
              result.length++;
          }
          else
          {
              type *temp = new type[lhs.length];
              for (int i = 0; i &lt; lhs.length; i++)
              {
                  temp[i] = lhs.items[i];
              }
              result.items = new type[lhs.length + 1];
              for (int i = 0; i &lt; lhs.length; i++)
              {
                  result.items[i] = temp[i];
              }
              result.items[lhs.length] = t;
              result.length++;
          }
          return result;
      }
  }
  
  template &lt;class type&gt;
  myList&lt;type&gt;::myList()
  {
      length = 0;
      items = new type;
      items = NULL;
  }
  </code></pre>
  
  <p>So what should be done in this case?</p>
  
  <p>EDIT: I fixed it. I had to remove &amp; from the return type. Is there any other possible way to fix it? or must &amp; be removed? </p>