Besart Dollma Besart Dollma - 1 year ago 67
C++ Question

Does a inherited class inherit a nested class?

I have an template class, for example

template<class T,class Key>
class BinaryTree:{
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 Source

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> {
    void rotateLL(typename AVLTree::node *n);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download