title: How to copy a stack?
body: <p>So I use a dynamic stack and I want to write a copy constructor, which has to copy the stack's data from another instance of the same class. I'm trying to write the function, but it seems pretty hard. Could somebody give me a hand?</p>
  
  <pre><code>template&lt;typename T=int&gt;
  class LStack
  {
  public:
  
      template&lt;typename U=int&gt;
      struct elem
      {
          U con;
          elem&lt;U&gt;* link;
      }
  
  private:
  
      elem&lt;T&gt;* el;
  
      void Copystack(Lstack const&amp; stack)    // HERE
      {
          elem&lt;T&gt;* last = el;
          el-&gt;con = stack-&gt;con;
          while(stack-&gt;link != null)
          {
              var temp = new elem&lt;T&gt;;
              temp-&gt;con = stack-&gt;con;
              temp-&gt;link = stack-&gt;link;
              stack = stack-&gt;link;
          }
      }
  
  };
  </code></pre>