我有一个使用模板的二进制搜索树类。所以我可以创建一个类型为Faculty的BST,但有没有办法在Faculty类中包含BST?
我想把一棵整数树作为Faculty类中的成员变量。
所以我会有一个Faculty树,每个节点(Faculty类型)都会有自己的整数树。
这是我试图添加BST成员变量的Faculty类。从我在其他地方读到的内容来看,问题在于试图#包含BST.h文件,因为我已经在BST文件中包含了教员文件。
#ifndef Faculty_H
#define Faculty_H
#include "Person.h"
#include "BST.h"
using namespace std;
class Faculty : public Person
{
public:
Faculty();
Faculty(int new_ID);
~Faculty();
friend ostream& operator<<(ostream& os, Faculty& f);
private:
BST<int> advisees;
};
#endif //Faculty_H
我的错误是:
/教员。h: 36:2:错误:未知类型名称“BST”
BST建议;
这是英国夏令时
#ifndef BST_H
#define BST_H
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include "tree_node.h"
#include "tree_node.cpp"
#include "Person.h"
#include "Student.h"
#include "Faculty.h"
using namespace std;
template <class T>
class BST
{
public:
BST();
~BST();
void insert(T k);
tree_node<T>* find(T k);
bool contains(T k);
bool delete_node(T k);
tree_node<T> *get_min();
tree_node<T> *get_max();
tree_node<T> *get_root();
bool is_empty();
int get_size();
void print_tree(tree_node<T> *node);
tree_node<T>* get_successor(tree_node<T> *d);
private:
tree_node<T> *root;
unsigned int size;
};
#endif //BST_H