Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unrecognizable template declaration/definition

Tags:

c++

templates

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;
}
like image 852
Oren Bell Avatar asked Jan 15 '16 22:01

Oren Bell


1 Answers

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;
}
like image 83
Pete Becker Avatar answered Sep 20 '22 07:09

Pete Becker