G'day guys, so I've decided to utilise generalisation for a UDT library to make further projects easier, however I've hit a snag regarding the declaration and specific syntax despite scouring the internet for possible answers to my conundrum.
Firstly, I have the following two shell classes, both template:
//Nodes.h
#pragma once
#include "LinkedList.h"
template <class T>
class LLNode
{
LLNode(T _data, LinkedList* parent);
private:
T data;
LLNode* next;
};
And
//LinkedList.h
#pragma once
#include "Nodes.h"
template <class T>
class LinkedList
{
LLNode* first;
LLNode* last;
int size;
LinkedList(T data);
void insert(T data, int index);
void append(T data);
void insert(LLNode* node, int index);
void append(LLNode* node);
};
Now, the problem is that no matter what I do, I can't seem to resolve the following error: "error C2601: syntax error: identifier 'LinkedList'" regarding the constructor shell for the LLNode template.
My main question is how do you, if possible, use template classes as a parameter type and what syntactic errors am I overlooking regarding the rest?
First, LLNode is a class template, so you need
LLNode<T>* first;
void insert(LLNode<T>* node, int index);
and so on.
Second, you have a cyclic include dependency between Nodes.h and LinkedList.h. You will have to re-design your code such that the classes don't depend on each other, or use forward declarations. You might have to play around with where you place the includes, which will be required for the implementations of your member functions. I suggest a re-design.
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