c ++用于模板继承类的体系结构x86_64的未定义符号

时间:2016-10-21 21:36:04

标签: c++ templates inheritance

我查看了有关此相同错误消息的SO上已经提出的其他问题。他们说要确保我的定义符合我的实现,而且(我认为)。我有多个类,linkedListType(基本模板类),unorderedLinkedList(派生模板类),main用于测试它和其他一些类(如果需要可以发布片段)。

编译时,我收到此错误:

Undefined symbols for architecture x86_64:
  "linkedListType<int>::deleteAtIndex(int&)", referenced from:
      deleteKthElement(unorderedLinkedList<int>&) in main.cpp.o
  "linkedListType<int>::getInfoAtIndex(int)", referenced from:
      printKthElement(unorderedLinkedList<int>&) in main.cpp.o
      deleteKthElement(unorderedLinkedList<int>&) in main.cpp.o
  "linkedListType<int>::linkedListType()", referenced from:
      unorderedLinkedList<int>::unorderedLinkedList() in main.cpp.o
  "linkedListType<int>::~linkedListType()", referenced from:
      unorderedLinkedList<int>::~unorderedLinkedList() in main.cpp.o
  "unorderedLinkedList<int>::deleteNode(int const&)", referenced from:
      vtable for unorderedLinkedList<int> in main.cpp.o
  "unorderedLinkedList<int>::insertLast(int const&)", referenced from:
      vtable for unorderedLinkedList<int> in main.cpp.o
  "unorderedLinkedList<int>::insertFirst(int const&)", referenced from:
      vtable for unorderedLinkedList<int> in main.cpp.o
  "unorderedLinkedList<int>::deleteSmallest()", referenced from:
      vtable for unorderedLinkedList<int> in main.cpp.o
  "unorderedLinkedList<int>::deleteAllOccurrences(int&)", referenced from:
      vtable for unorderedLinkedList<int> in main.cpp.o
  "unorderedLinkedList<int>::deleteFirstOccurrence(int&)", referenced from:
      vtable for unorderedLinkedList<int> in main.cpp.o
  "linkedListType<int>::printListReverse() const", referenced from:
      reversePrint(unorderedLinkedList<int>&) in main.cpp.o
  "linkedListType<int>::print() const", referenced from:
      print(unorderedLinkedList<int>&) in main.cpp.o
  "linkedListType<int>::length() const", referenced from:
      printKthElement(unorderedLinkedList<int>&) in main.cpp.o
      deleteKthElement(unorderedLinkedList<int>&) in main.cpp.o
  "unorderedLinkedList<int>::search(int const&) const", referenced from:
      vtable for unorderedLinkedList<int> in main.cpp.o

查看第一个(deleteAtIndex):

linkedListType.h

template<class Type>
class linkedListType {
public:
   ...
   void deleteAtIndex(int& desiredIndex);
}

linkedListType.cpp

template<class Type>
void linkedListType<Type>::deleteAtIndex(int& desiredIndex) {
    nodeType<Type> *temp = getNodeAtIndex(desiredIndex);
    nodeType<Type> *priorNode = getNodeAtIndex(desiredIndex-1);
    priorNode->link = temp->link;
    delete temp;
}

main.cpp

// a convenience function in main.cpp... both 'getInfoAtIndex' and 'deleteAtIndex' only exist in the base class
void deleteKthElement(unorderedLinkedList<int> &ull){ 
    int elem;
    cout << "Enter an integer specifying the index to delete (0 - " << ull.length() - 1 << "): ";
    cin >> elem;
    int info = ull.getInfoAtIndex(elem);
    cout << "Info at index (" << elem << "): " << info << endl;
    ull.deleteAtIndex(elem);
    cout << "Node deleted." << endl;
}

我不知道为什么这些功能会给我这些错误。

0 个答案:

没有答案