2017-04-24 17 views
-2
template<class Type> 
Type* unorderedLinkedList<Type>:: newSearch(nodeType<Type> *head, const Type& x)const 
{ 
    if (head == NULL) 
     return 0; 

    if (head->info == x) 
     return ???(head or *head?); 

    return newSearch(head->link, x); 
} 

template <class Type> 
Type* unorderedLinkedList<Type>::recursiveLinkSeqSearch(const Type& item) const 
{ 
    nodeType<Type> *current; 
    current=this->first; 
    return newSearch(current, item); 


} 

이제이 질문에 대한 어리 석을 느끼지만이 함수의 반환 값을 알 수 없습니다. 주 코드에서 나는 bool 같은 것을 돌려 줄 필요가있다. 메인은 비슷한 모양입니다.ADT를 사용하여 적절한 반환 값을 가져올 수 없습니다.

unorderedLinkedList<classType> l1; 
    classType *st; 
    l1.recursiveLinkSeqSearch(st); 
    if(l1){}else{}; 

필자는 기능에 많은 변화를 주었고 실제로 어떤 도움을 주셔서 감사합니다.

+0

가 반환 헤드 있어야한다 보인다 데이터 유형의 문제를 해결. 어떤 오류 메시지가 나타 났습니까? – Shiping

+0

"nodeType * –

+0

유형의 값이있는 반환 유형 객체 'dataType *'을 초기화 할 수 없습니다."Type * unorderedLinkedList:: newSearch (nodeType * head, const Type & x) const "를 변경하는 방법은 다음과 같습니다. "형식 * unorderedLinkedList :: newSearch ( * head, const Type & x) const"그냥 noteType을 제거하십시오. – Shiping

답변

0

내게는 '머리'를 돌려 주어야합니다. 종류가 정말 그들이있는 상태를 유지해야하는 경우, 당신은 타입 캐스트해야 할 것 :

그러나

return (Type*)head; 

을, 어쩌면 당신이 대신하고 싶은 당신의 함수의 반환 값을 변경할 수있다

template<class Type> 
nodeType<Type>* unorderedLinkedList<Type>:: newSearch(nodeType<Type> *head, const Type& x)const 
{ 
// Function body 
} 

template <class Type> 
nodeType<Type>* unorderedLinkedList<Type>::recursiveLinkSeqSearch(const Type& item) const 
{ 
// Function body 
} 

세부 정보를 알지 못해도 확실하게 알기는 어렵습니다. 그렇기 때문에 다른 것도하고 싶을 수도 있습니다.

return &head->info; 

위의 설명에서와 같이

+0

타입 캐스트가 링커 오류를 일으켰습니다.하지만이 프로그램은 학교용으로 작동하기 때문에 recursiveLinkSeqSearch에서 param을 변경할 수 없습니다. bool을 반환하거나 가치와 같이 bool 할 필요가있다. –

0

이 클래스의 모든 문제를 해결하고