我有一个链接列表类列表。我必须为它制作复制构造函数。我实际上遇到了语法问题。这里是我的代码:链接列表类的复制构造函数
template <class T>
List<T>::List(const List<T>& otherList)
{
}
otherList是另一种类型的List。事实上,我认为这是一个指向List的指针。我有一个为类List定义的getHead()函数,它的工作正常。 我想执行以下操作将确定:
Node* temp = otherList->getHead();
节点是的名单是由指针。这是一个独立的类节点。 但做上述给出了错误:
base operand of -> has non-pointer type const List<int>
,所以我试图用“”而不是上面表达式中的“ - >”。得到了以下错误:
passing const List<int> as this argument of ListItem<T>* List<T>::getHead() [with T = int] discards qualifiers [-fpermissive]
我getHead功能:
template <class T>
node<T>* List<T>::getHead()
{
return head;
}
亲切指导我
是什么让你认为它是一个指针? –
外来列表引用是const。因此您只能使用它的const成员,并且您从中检索的数据成员都是相同的。 – WhozCraig