I am trying to implement insertOrdered
class method for double-linked list in C++ (I am newbie to C++). The issue are errors which originate from defined util functions (non class functions) which are called from insertOrdered
method. The g++ compiler shows the errors which are written here as comments: //error: ....
Can someone tell me how to resolve the errors. Thanks.
LinkedList.h:
template <typename T>
class LinkedList
{
public:
class Node
{
public:
Node* next;
Node* prev;
T data;
...
}
void insertOrdered(const T& newData);
private:
Node* head;
...
}
Task.h:
#include "LinkedList.h"
template <typename T>
bool insertWhenEmpty(LinkedList<T> list, const T& data)
{
auto newNode = new LinkedList<T>::Node(data); //error: expected type-specifier
....
}
template <typename T>
void insertBefore(LinkedList<T> list, LinkedList<T>::Node curr, const T& data)
{
//error: LinkedList<T>::Node curr -> use the 'typename' keyword to treat nontype "LinkedList<T>::Node [with T=T]" as a type in a dependent context
....
}
template <typename T>
void LinkedList<T>::insertOrdered(const T& newData)
{
if (insertWhenEmpty(this, newData))
return;
....
auto curr = this->head;
insertBefore(this, curr, newData);
....
}