Trying to copy a LinkedList of ItemType.
Excerpt from main.cpp
LinkedList<ItemType> LLobject;
// codes that insert data to object ItemType
LinkedList<ItemType> copyLLobject(LLobject);
Excerpt from Node.cpp
template<class ItemType>
Node<ItemType>::Node() : next(0) { } // ERROR ACKNOWLEDGED BY COMPILER
Error message from compiler
error: no matching function for call to 'ItemType::ItemType()'
If it helps, here are the codes for LinkedList constructor in LinkedList.cpp
template<class ItemType>
LinkedList<ItemType>::LinkedList(const LinkedList<ItemType>& aList) : itemCount(aList.itemCount)
{
Node<ItemType>* origChainPtr = aList.headPtr; // Points to nodes in original chain
if (origChainPtr == 0)
headPtr = 0; // Original list is empty
else
{
// Copy first node
headPtr = new Node<ItemType>();
headPtr->setItem(origChainPtr->getItem());
// Copy remaining nodes
Node<ItemType>* newChainPtr = headPtr; // Points to last node in new chain
origChainPtr = origChainPtr->getNext(); // Advance original-chain pointer
while (origChainPtr != 0)
{
// Get next item from original chain
ItemType nextItem = origChainPtr->getItem();
// Create a new node containing the next item
Node<ItemType>* newNodePtr = new Node<ItemType>(nextItem);
// Link new node to end of new chain
newChainPtr->setNext(newNodePtr);
// Advance pointer to new last node
newChainPtr = newChainPtr->getNext();
// Advance original-chain pointer
origChainPtr = origChainPtr->getNext();
} // end while
newChainPtr->setNext(0); // Flag end of chain
} // end if
} // end copy constructor
EDIT:
I have two constructors of ItemType in ItemType.cpp
Default Constructor
ItemType::ItemType() { }
Overloading Constructor
ItemType::ItemType( string t = "", string q = "", string a = "", int p = 0 )
: t(t), q(q), a(a), p(p) { }