I am trying to make a circular doubly linked list, and thought it was a good idea to implement it as a template, since I will be using this kind of lists in my project.
The problem is, that while I think to my understanding that I have done everything right, my compiler beg to differ.
The error messages I get are:
- "Unknown type name 'node'"
- "Expected member name or ';' after declaration specifiers"
I get these two messages for each of the offending lines, and everything seems right to me. I am sure there is something I am lacking in understanding or something.
My template class:
#include <stdio.h>
template <typename T>
class Node {
private:
T *mData;
Node<T> *mPreviousNode;
Node<T> *mNextNode;
Node<T> *mChildNode;
protected:
public:
Node();
~Node();
};
template <typename T>
Node<T>::Node() {
mData = nullptr;
mPreviousNode = nullptr;
mNextNode = nullptr;
mChildNode = nullptr;
}
template <typename T>
Node<T>::~Node() { }
The header class with the offending lines:
#include <stdio.h>
class Path {
private:
Node<Point> *mPointListHead; // <<---- THIS LINE,
Node<Point> *mPointListTail; // <<---- AND THIS LINE
protected:
public:
Path();
~Path();
void addPoint(float x, float y, float z);
};
The Implementation for the class:
#include "Node.h"
#include "Point.h"
#include "Path.h"
Path::Path() {
mPointListHead = nullptr;
mPointListTail = nullptr;
}
Path::~Path() {
}
void Path::addPoint(float x, float y, float z) {
printf("Adding point\n");
}
The header file for the Point class just for reference:
#include <stdio.h>
class Point {
private:
float mX, mY, mZ;
float mR, mG, mB, mA;
protected:
public:
Point();
Point(float x, float y, float z);
Point(float x, float y, float z, float r, float g, float b, float a);
~Point();
};
The implementation of Point:
#include "Point.h"
Point::Point() : Point(0.0f, 0.0f, 1.0f) { }
Point::Point(float x, float y, float z) : Point(x, y, z, 1.0f, 1.0f, 1.0f, 1.0f) { }
Point::Point(float x, float y, float z, float r, float g, float b, float a) {
mX = x; mY = y; mZ = z;
mR = r; mG = g; mB = b; mA = a;
}
Point::~Point() {
}
Thanks for any help with this, and yes, I know that classes are private by default.
EDIT: The weird thing is that the "intellisense" (*) kind of thing sometimes seem to colour the keywords like it understand the names, but when I try to compile again, it forgets them again. When the names are in the colours that shows that the IDE knows the class names, I can also start typing and get the correct autocomplete suggestions. Also this goes away if I try to compile. I am using the latest Xcode by the way, but I am pretty sure it is me goofing up, not the IDE/compiler.
(*) I don't know what name Apple has for the "intellisense".