I'm having a weird error saying my class is getting redefined, stemming from the declaration of friend in my Node class. Here's my current code:
template <class T>
class Node {
private:
T val;
Node<T> * next;
public:
friend class OList;
};
Any my other 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;
}
OList
is not a class, it's a class template. You can either friend all specializations of the template:
template <typename> friend class OList;
or friend a specific specialization:
friend class OList<T>;
which will require OList
to already be declared. Put a forward declaration before the definition of Node
:
template <typename> class OList;
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