没有用于调用' ItemType :: ItemType()'的匹配函数

时间:2017-02-10 04:27:15

标签: c++ class oop object

尝试复制ItemType的LinkedList。

摘自main.cpp

LinkedList<ItemType> LLobject;
// codes that insert data to object ItemType
LinkedList<ItemType> copyLLobject(LLobject);

摘自Node.cpp

template<class ItemType>
Node<ItemType>::Node() : next(0) { } // ERROR ACKNOWLEDGED BY COMPILER

来自编译器的错误消息

error: no matching function for call to 'ItemType::ItemType()'

如果有帮助,这里是LinkedList.cpp

中的LinkedList构造函数的代码
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

编辑:

我在ItemType.cpp中有两个ItemType构造函数

默认构造函数

ItemType::ItemType() { }

重载构造函数

ItemType::ItemType( string t = "", string q = "", string a = "", int p = 0 )
        : t(t), q(q), a(a), p(p) { }

0 个答案:

没有答案