title: Adding values of two stacks of the same size
body: <p>I'm just practicing creating a stack class and I'm trying to overload <code>operator=</code> and <code>operator+</code>. So far I have successfully overloaded the <code>operator=</code>.</p>
  <p>Let's say my objective is to be able to do <code>st3 = st1 + st2;</code> operation in the main where st1, st2, st3 are the objects of class stack and assuming they all have the same size and are all int values.</p>
  <p>Right now st3 is not returning any values.</p>
  <p>In my class I had:</p>
  <pre><code> stack&amp; operator+(stack&amp; otherStack){
          int sum = 0;
          stack res;
          while ((!this-&gt;isEmpty()) &amp;&amp; (!otherStack.isEmpty())) {
              sum = this-&gt;top() + otherStack.top();
              res.push(sum);
              this-&gt;pop();
              otherStack.pop();
          }
          return res;
      }
  </code></pre>
  <p>And here is my <code>print()</code> function using recursion which is also in <code>class stack</code>. It prints st1 and st2 just fine</p>
  <pre><code>void printStack(){
          if (isEmpty())
              return;
          int x = this-&gt;top();
          this-&gt;pop();
          this-&gt;printStack();
          this-&gt;push(x);
      }
  </code></pre>