I'm trying to implement a heap, but I've got the above error on one of my functions.
Here's my header file:
template <typename E>
class Heap
{
private:
class Node {
E data;
Node * left;
Node * right;
};
Node root;
int length;
E * preorder(E * list, int length, Node node);
E * inorder(E * list, int length, Node node);
E * postorder(E * list, int length, Node node);
void clear(Node node); //Recursively clears all nodes and frees all pointers
public:
Heap();
Heap(E * list, int length);
~Heap();
Node * getRoot();
void buildHeap(E * list, int length);
E * returnList();
};
And the specific function in question (although there's similar errors on others). There error is on the second line
template <typename E>
Node<E> * Heap<E>::getRoot() {
return &root;
}
The compiler is complaining about Node<E>
; there is no template named Node
in global scope. The code has to say that it's the member template:
template <typename E>
typename Heap<E>::Node * Heap<E>::getRoot() {
return &root;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With