函数实现与头文件原型完全匹配,但仍然出现错误

时间:2018-10-16 23:19:23

标签: c++

我从其中一个函数说

时出错
LinkedSortedList.cpp:141:18: error: prototype for ‘Node<ItemType>* LinkedSortedList<ItemType>::copyChain(const Node<ItemType>*)’ does not match any in class ‘LinkedSortedList<ItemType>’
 Node<ItemType> * LinkedSortedList<ItemType>::copyChain(const Node<ItemType> * origChainPtr)
                  ^
LinkedSortedList.h:18:26: error: candidate is: Node<ItemType>* LinkedSortedList<ItemType>::copyChain(const Node<ItemType>&)
         Node<ItemType> * copyChain(const Node<ItemType> * origChainPtr);
                      ^

即使函数声明完全匹配。

以下是函数和原型:

在LinkedSortedList.cpp中:

template<class ItemType>
Node<ItemType> * LinkedSortedList<ItemType>::copyChain(const Node<ItemType> * origChainPtr)
{
    Node<ItemType> * copiedChainPtr; // Initial value is nullptr
    if (origChainPtr != NULL)
    {
        copiedChainPtr = new Node<ItemType>(origChainPtr->getItem(), NULL);
        // Make the node point to the rest of the chain
        copiedChainPtr->setNext(copyChain(origChainPtr->getNext()));
    } // end if
    return copiedChainPtr;
}

在LinkedSortedList.h中:

编辑:整个.h文件

     #ifndef LINKED_SORTED_LIST_
#define LINKED_SORTED_LIST_
#include <memory>
#include <iostream>
#include "Node.h"

template<class ItemType>
class LinkedSortedList 
{
    private:

        Node<ItemType> * headPtr; // Pointer to first node in chain
        int itemCount; // Current count of list items
        // Locates the node that is before the node that should or does contain the given entry
        Node<ItemType> * getNodeBefore(const ItemType& anEntry) const;
        // Locate the node at a given position within the chain
        Node<ItemType> * getNodeAt(int position) const;
        // Returns a pointer to a copy of the chain to which origChainPtr points
        Node<ItemType> * copyChain(const Node<ItemType> * origChainPtr);
    public:
        LinkedSortedList();
        LinkedSortedList(const LinkedSortedList<ItemType>& aList);
        virtual ~LinkedSortedList();
        bool insertSorted(const ItemType& newEntry);
        bool removeSorted(const ItemType& anEntry);
        int getPosition(const ItemType& entry);
        // following methods are the same as given in ListInterface
        bool isEmpty() const;
        int getLength() const;
        bool removePosition(int position);
        void clear();
        ItemType getEntry(int position) const;
};
#endif

0 个答案:

没有答案