Class rename error

I have a strange error when my class is redefined based on the declaration of a friend in the Node class. Here is my current code:

template <class T>
class Node {

private:

    T val;
    Node<T> * next;

public:

    friend class OList;

};

Any of my class:

template <class T>
class OList {  ------> Error here

private:

    Node<T> * head;
    int size;

public:

    OList();
    OList(const OList<T> &b);
    ~OList();

    clear();
    int size();
    T tGet(int input);
    int count(T input);
    insert (T input);
    remove (T input);
    uniquify(T input);
    Node<T> * returnHead();

};

// Constructs empty list
template <class T>
OList<T>::OList() { ---> Error here
    head = NULL;
    size = 0;
}
+4
source share
1 answer

OListnot a class, this is a class template. You can either get around all the template specializations:

template <typename> friend class OList;

or a friend with a specific specialization:

friend class OList<T>;

for which you want to OListalready declare. Before defining, Nodeput forward declaration:

template <typename> class OList;
+8
source

All Articles