title: return a list<int> from a function c++
body: <p>Every time I try to use my add function and return a list from it. I get an undefined symbol error. What am I doing wrong here. </p>
  
  <p>this is the error:
  Undefined                       first referenced
   symbol                             in file</p>
  
  <pre><code>add(std::list&lt;int, std::allocator&lt;int&gt; &gt; const&amp;, std::list&lt;int, std::allocator&lt;int&gt; &gt;)/var/tmp//cc78hUrW.o
  </code></pre>
  
  <p>ld: fatal: Symbol referencing errors. No output written to a.out
  collect2: ld returned 1 exit status</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;list&gt;
  #include &lt;math.h&gt;
  
  using namespace std;
  
  list&lt;int&gt; add(const list&lt;int&gt; &amp;lhs, const list&lt;int&gt; $rhs);
  list&lt;int&gt; sub(const list&lt;int&gt; &amp;lhs, const list&lt;int&gt; $rhs);
  list&lt;int&gt; mul(const list&lt;int&gt; &amp;lhs, const list&lt;int&gt; &amp;rhs);
  
  int main(int argc, char* argv[])
  {
      /*variables*/
      list&lt;int&gt; num1, num2, num3;
      list&lt;int&gt; ::iterator it1, it2, it3;
      char temp[1001];
      int x = 0, y = 0;
  
      it1 = num1.begin();
  
      for(x = 0; x &lt;= 1001; x++)
          temp[x] = -42;
  
      cout &lt;&lt; "Number 1: ";
      cin &gt;&gt; temp;
  
      for(x = 0; temp[x] != -42; x++)
          num1.insert(it1, temp[x] - '0');
  
      for(x = 0; x &lt;= 1001; x++)
          temp[x] = -42;
  
      cout &lt;&lt; "Number 2: ";
      cin &gt;&gt; temp;
  
      it2 = num2.begin();
  
      for(x = 0; temp[x] != -42; x++)
          num2.insert(it2, temp[x] - '0');
  
      it1 = num1.end();
      it1--;
      num1.erase(it1);
  
      for(it1 = num1.begin(); it1 != num1.end(); it1++)
           cout &lt;&lt; *it1;
      cout &lt;&lt; endl;
  
      it2 = num2.end();
      it2--;
      num2.erase(it2);
  
      for(it2 = num2.begin(); it2 != num2.end(); it2++)
      cout &lt;&lt; *it2;
      cout &lt;&lt; endl;
  
      num3 = add(num1, num2);
  
      for(it3 = num3.begin(); it3 != num3.end(); it3++)
      cout &lt;&lt; *it3;
      cout &lt;&lt; endl;
  
      return 0;
      }
  
      list&lt;int&gt; add(const list&lt;int&gt; &amp;lhs,const list&lt;int&gt; &amp;rhs)
      {
      /*Variables*/
      list&lt;int&gt; left = lhs;
      list&lt;int&gt; right = rhs;
      list&lt;int&gt; answer;
      list&lt;int&gt;::iterator itl, itr, ans;
      int cary = 0;
      int sum = 0;
      int lfint = 0, rtint = 0;
      int lsize=0, rsize=0;
  
      lsize = (int)left.size();
      rsize = (int)right.size();
  
      while(lsize &lt; rsize)
      {
          itl = left.end();
          left.insert(itl, 0);
          lsize = (int)left.size();
      }
  
      while(rsize &lt; lsize)
      {
           itr = right.end();
           right.insert(itr, 0);
           rsize = (int)right.size();
      }
  
      itl = left.begin();
      itr = right.begin();
      ans = answer.begin();
  
      while(itl != left.end())
      {
           lfint = *itl;
           rtint = *itr;
           sum = lfint + rtint;
  
           sum = sum + cary;
           cary = 0;
  
           if(sum &gt;= 10)
           {
               sum = sum - 10;
               cary = 1;
           }
  
           answer.insert(ans, sum);
           itl++;
           itr++;
      }
      if(cary == 1)
      {
          answer.insert(ans, 1);
      }
  
      return answer;
      }
  </code></pre>