我正在研究一个名为“BinarySearchTree”的子类,它继承自超类“BinaryTree”
BinaryTree.h
template <class T>
class BinaryTree
{
public:
BinaryTree() { root = NULL; }
protected:
BTNode<T> *root; // Root node (NULL if the tree is empty)
};
BinarySearchTree.h
template <class T>
class BinarySearchTree : public BinaryTree<T>
{
public:
BinarySearchTree(); // call super's
bool insert( const T& elem );
bool insertHelper(BTNode<T> *&, T );
};
template<class T>
BinarySearchTree<T>::BinarySearchTree() : BinaryTree<T>()
{
root = NULL; // <---- error: In constructor 'BinarySearchTree<T>::BinarySearchTree()'
//: BinarySearchTree.h:85: error: ‘root’ was not declared in this scope
};
我知道这与根目录中未被识别的根有关,但我该如何解决这个问题呢?
答案 0 :(得分:1)
例如:
BinaryTree<T>::root = NULL;
请参阅此处获取解释:
http://www.parashift.com/c++-faq/nondependent-name-lookup-members.html