c++ - 未定义的对 `BST 的引用::BST()'
问题描述
我收到这些错误
C:\Users\SDRav\AppData\Local\Temp\ccCy0RiX.o:driver.cpp:(.text+0x1b): 未定义对BST<char>::BST()'
C:\Users\SDRav\AppData\Local\Temp\ccCy0RiX.o:driver.cpp:(.text+0x1eb): undefined reference to
BST::insert(char const&)' C:\Users\SDRav\AppData\Local 的引用\Temp\ccCy0RiX.o:driver.cpp:(.text+0x228): 未定义对BST<char>::traversePreorder(BSTNode<char>*)'
C:\Users\SDRav\AppData\Local\Temp\ccCy0RiX.o:driver.cpp:(.text+0x263): undefined reference to
BST::search(char const&) const' C:\Users\SDRav\AppData\Local\Temp\ccCy0RiX.o:driver 的引用。 cpp:(.text+0x32b): 未定义对BST<char>::deleteNode(char const&)'
C:\Users\SDRav\AppData\Local\Temp\ccCy0RiX.o:driver.cpp:(.text+0x419): undefined reference to
BST::leafCount(BSTNode*)' C:\Users\SDRav\AppData\Local\Temp\ccCy0RiX.o:driver.cpp:(.text+0x47c) 的引用:未定义参考BST<char>::search(char const&) const'
C:\Users\SDRav\AppData\Local\Temp\ccCy0RiX.o:driver.cpp:(.text+0x4d5): undefined reference to
BST::getSiblings(char const&)' collect2.exe: error: ld returned 1 exit status
但我不知道为什么....我的猜测是链接但我检查了标题但我仍然看不到它
我的驱动程序.cpp(主要)
#include <iostream>
#include <iomanip>
#include "BST.h"
using namespace std;
int main()
{
BST<char> op1;
int action = 0;
int numInsert = 0;
char value;
cout<<"-------------------- MENU ----------------------"
<<endl<<"1. Insert node(s)"
<<endl<<"2. Traverse Preorder"
<<endl<<"3. Search BST"
<<endl<<"4. Delete node"
<<endl<<"5. Leaf Count"
<<endl<<"6. Sibling of a node"
<<endl<<"7. Quit"
<<endl<<"Please ent
switch (action)
{
case 1:
cout << "\n How many values would you liek to insert to a BST? ";
cin>>numInsert;
for(int i =0; i<numInsert;i++){
cout<<"What value would you like to insert to the list: ";
cin >> value;
op1.insert(value); //check
}
break;
...
}
--- BST.h ---
#include <iostream>
#include "BSTNode.h"
using namespace std;
#ifndef BINARY
#define BINARY
template <typename DataType>
class BST
{
public:
BST();
// ~BST();
bool empty() const;
/*------------------------------------------------------------------------
Check if BST is empty.
Precondition: None.
Postcondition: Returns true if BST is empty and false otherwise.
-----------------------------------------------------------------------*/
void insert(const DataType & item);
void traversePreorder(BSTNode<DataType> * startPoint);
bool search(const DataType & item)const;
bool deleteNode(const DataType & item);
int leafCount(BSTNode<DataType> * startPoint);
DataType getSiblings(const DataType & item);
private:
BSTNode<DataType> * treeRoot;
typedef BSTNode<DataType> * BSTNodePointer;
void search2(const DataType & item, bool & found, BSTNodePointer & locptr, BSTNodePointer & parent) const;
};
请帮忙
解决方案
推荐阅读
- reactjs - 如何使用从承诺返回的函数取消订阅 useEffect?
- excel - 如果是季度的第 1 2 3 个月,如何识别 Excel 中的公式?
- python - 使用 BeautifulSoup 查找特定的 span 元素
- python - 如何在 Django 模板中获得反向引用?
- r - R根据列数据创建箱线图
- elasticsearch - Kibana / Elastic - 不能使用数组字段
- loops - “ValueError:要解压的值太多(预期为 2)”不应在此处发生
- javascript - JavaScript - 通过 Flask 获取列表中的第 i 个元素
- reactjs - 在 TailwindCss 中动态构建类名
- c# - .Net Core Web API 分页列表 - 源“IQueryable”的提供程序未实现“IAsyncQueryProvider”