我有这个大学项目,我必须使用模板创建一个BinarySearchTree类。我们必须根据文件中的数据类型读取文件并创建树。我为名为BST的树创建了一个父类,因此我可以使用树而不给它类类型。
class BST{
public:
BST();
~BST();
}
树
template <class T> class BinarySearchTree : public BST{
public:
void add(T val);
}
我想这样做:
BST tree = BinarySearchTree<int>(); //just an example, it can be of any type
tree.add(5); //doesn't work
如何在不提供特定变量类型的情况下从BST调用“add”?
答案 0 :(得分:-1)