I am working on a linked list class which contains a private nested node class. I want to advance n nodes forward in my list by using the overloaded addition operator but clang is giving me the error "overloaded 'operator+' must be a unary or binary operator (has 3 parameters)". I thought that the implicit this parameter disappeared when you declared it as a friend function.
First is my header file
template <class T>
class List
{
private:
class ListNode
{
public:
ListNode();
ListNode(const T& ndata);
friend ListNode* operator+(const ListNode* &node, int n);
ListNode* next;
ListNode* prev;
};
public:
friend ListNode* operator+(const ListNode* &node, int n);
and my implementation is as follows:
template <class T>
typename List<T>::ListNode* List<T>::ListNode::operator+(const ListNode* &node, int n)
{
ListNode* current = node;
while (n--){
if (current->next != 0)
current = current->next;
}
return current;
}