Besart Dollma Besart Dollma - 9 days ago 7
C++ Question

Does a inherited class inherit a nested class?

I have an template class, for example

template<class T,class Key>
class BinaryTree:{
public:
class node {};
}


and now I want to inherit from the class, for example:

class AVLTree : public Binary Tree


The problem I get stuck with is that the functions I want to implement in AVLTree don't recognize the node. For example let the function be

void rotateLL(node* n)


The compiler says:

node has not been declared


How can I solve this?

Answer

node is what's called a dependent name, since it's a member of the base class which depends on template parameters. You need:

template <class T, class Key>
class AVLTree : public BinaryTree<T, Key> {
public:
    void rotateLL(typename AVLTree::node *n);
};