mercredi 9 août 2017

Undeclared identifier when using a template class with a templated variable

I have a Tree class with Nodes. The Tree should be instantiated using a template, so that a user can retrieve Nodes with a templated Payload.

This is my header:

// The Node
template <typename T>
struct Node {
public:
    bool leaf;
    double minX;
    double minY;
    double maxX;
    ...
    T payload;
};

// The Tree class
    template <typename T>
    class Tree {
    public:
        Tree(int maxEntries = 9);
        Node<T> *data() { return _data; };

    private:
        Node<T> *_data;
        bool intersects(Node<T> &a, Node<T> &b);
        ...
}

The problem I face is that the header seems ok, but in the cpp the compiler complains with "Use of undeclared identifier 'T'":

bool Tree::intersects(Node<T> &a, Node<T> &b) {
    return b.minX <= a.maxX &&
    b.minY <= a.maxY &&
    b.maxX >= a.minX &&
    b.maxY >= a.minY;
 }

How should I fix it so that I can instantiate a Tree using the template T for it's Nodes?

Aucun commentaire:

Enregistrer un commentaire