Copy constructor for a stack using linked list
<pre><code>template &lt;class T&gt;
Stack&lt;T&gt;::Stack(const Stack&lt;T&gt;&amp; otherStack)
{
        List&lt;T&gt; the=otherStack.list;
        ListItem&lt;T&gt; *temp=the.getHead();
        while(temp!=NULL)
        {
                push(temp-&gt;value);
                temp=temp-&gt;next;
        }
}
</code></pre>

<p>I am using a linked list to make a stack and my copy constructor is not working. Please someone help.</p>

<p>The copy constructor of <code>List&lt;T&gt;</code> is defined as:</p>

<pre><code>template &lt;class T&gt;
List&lt;T&gt;::List(const List&lt;T&gt;&amp; otherList)
{
    head=NULL;
    ListItem&lt;T&gt; *temp=otherList.head;

    while (temp!=NULL)
    {
        insertAtTail(temp-&gt;value);
        temp=temp-&gt;next;
    }
}
</code></pre>
