[英]c++ function return type error
在編寫函數以提取鏈表的最小值時,我在返回類型方面遇到了問題,我正在使用模板,並且試圖將模板的類型更改為所需的類型。 我該怎么辦。 謝謝 :)
這是代碼:
Type linkedListType<Type>::extractMin()const{
assert (last!=NULL);
nodeType<Type> *current;
nodeType<Type> *minval;
current = first;
minval=first;
while (current != NULL) //search the list
{
if (current->info < minval->info) //searchItem is found
{
minval=current;
current=current->link;
}
else
current = current->link; //make current point to next node
}
return minval;}
您的功能已簽名
Type linkedListType<Type>::extractMin() const
但是你嘗試返回
return minval;
哪種類型
nodeType<Type>* minval;
因此,當您說要返回Type
時,您將返回nodeType<Type>*
。
類型linkedListType :: extractMin()const
您將返回Type
。
nodeType *最小值
但是,您試圖return minval
但是minval
的類型為nodeType<Type>*
(即,您沒有返回Type
)。
相反,您可能需要將其中一個成員返回minval
。 例如類似
return minval->value;
但由於我們不知道nodeType
的代碼是什么樣子,因此無法確切說明如何解決該問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.