请版里的大侠们帮忙看一下,该如何处理
请版里的大侠们帮忙看一下
共4个文件,分别是TNode.h(节点文件类), BST.h,BST.cpp(二叉树类),TestTree.cpp(主程序)
代码如下:
TNode.h:
BST.h:
BST.cpp:
TreeTest:
这是个binary search tree,还没有写完,只是想测试一下Insert函数的正确性。但编译报错,编译错误提示如下:
1>TreeTest.obj : error LNK2019: unresolved external symbol "public: bool __thiscall BST<int>::Insert(int const &)" (?Insert@?$BST@H@@QAE_NABH@Z) referenced in function _main
共4个文件,分别是TNode.h(节点文件类), BST.h,BST.cpp(二叉树类),TestTree.cpp(主程序)
代码如下:
TNode.h:
#ifndef TNODE_H
#define TNODE_H
template <typename T>
class TNode
{
public:
TNode(const T& val = T()):nodeValue(val), parent(NULL), left(NULL), right(NULL){}
private:
TNode<T> *parent, *left, *right;
T nodeValue;
};
#endif
BST.h:
#ifndef BST_H
#define BST_H
#include "TNode.h"
template <typename T>
class BST
{
public:
BST(TNode<T>* r = NULL):root(r){}
bool Insert(const T& val);
bool Search(const T& val) const;
bool Delete(const T& val);
void Print_InOrder(TNode<T>* r);
TNode<T>* getRoot() {return root;}
private:
TNode<T> *root;
};
#endif
BST.cpp:
#include <iostream>
#include "BST.h"
using namespace std;
template <typename T>
bool BST<T>::Insert(const T& val)
{
bool ins = false;
bool find = false;
TNode<T> *curr = root;
while (!curr && !find)
{
if(val < curr->nodeValue)
curr = curr->left;
else if (val > curr->nodeValue)
curr = curr->right;
else
find = true;
}
if(!find)
{
curr = new TNode(val);
ins = true;
}
return ins;
}
template <typename T>
bool BST<T>::Search(const T& val) const
{
}
template <typename T>
bool BST<T>::Delete(const T& val)
{
}
template <typename T>
void BST<T>::Print_InOrder(TNode<T>* r)
{
if(r)
{
Print_InOrder(r->left);
cout << r->nodeValue;
Print_InOrder(r->right);
}
}
TreeTest:
#include <iostream>
#include "TNode.h"
#include "BST.h"
using namespace std;
int main()
{
BST<int> btree;
int n;
for (int i = 0; i < 3; i++)
{
cout << "Please input a number" << endl;
cin >> n;
btree.Insert(n);
}
TNode<int> *root = btree.getRoot();
btree.Print_InOrder(root);
return 0;
}
这是个binary search tree,还没有写完,只是想测试一下Insert函数的正确性。但编译报错,编译错误提示如下:
1>TreeTest.obj : error LNK2019: unresolved external symbol "public: bool __thiscall BST<int>::Insert(int const &)" (?Insert@?$BST@H@@QAE_NABH@Z) referenced in function _main