template <class T>
Stack<T>::Stack(const Stack<T>& otherStack)
{
List<T> the=otherStack.list;
ListItem<T> *temp=the.getHead();
while(temp!=NULL)
{
push(temp->value);
temp=temp->next;
}
}
リンク リストを使用してスタックを作成していますが、コピー コンストラクターが機能していません。誰か助けてください。
のコピー コンストラクターList<T>
は次のように定義されます。
template <class T>
List<T>::List(const List<T>& otherList)
{
head=NULL;
ListItem<T> *temp=otherList.head;
while (temp!=NULL)
{
insertAtTail(temp->value);
temp=temp->next;
}
}