I've worked it into getting errors such as this:
error C2440: '=' : cannot convert from 'cLinkedList<T> *const ' to 'cEntity *' 1> with 1> [ 1> T=cEntity 1> ] 1> Cast from base to derived requires dynamic_cast or static_cast 1> c:\users\owner\documents\visual studio 2010\projects\rpg\rpg\clinkedlist.cpp(9) : while compiling class template member function 'int cLinkedList<T>::FindEmptyID(void)' 1> with 1> [ 1> T=cEntity 1> ]
And I'm quite confused about how to fix this.
Relevant code:
cLinkedList.h:
#pragma once
template <class T>
class cLinkedList
{
public:
T *next;
int FindEmptyID();
T * ScanListPrevious(int ID);
T * ScanList(int ID);
T * ScanListEnd(); // Returns the last entity in the list
};cLinkedList.cpp:
#include "cLinkedList.h"
#include "cTile.h"
#include "cEntity.h"
template <class T>
int cLinkedList <T>::FindEmptyID()
{
T *dummy, *dummyNext;
if(this != 0)
{
dummy = this;
while(true)
{
dummyNext = dummy->next;
if(dummyNext == 0)
{
// Impossible to dicern the next ID, assume that the final one in the list is the last ID
return dummy->ID + 1;
}
if(dummyNext->ID - dummy->ID > 1)
// This checks if there is a break between ID numbers and returns ID + 1 which fills the hole
return dummy->ID + 1;
dummy = dummy->next;
}
}
else
{
// Error, no root
}
}
template <class T>
T * cLinkedList <T>::ScanListPrevious(int ID)
{
T *previous; // Dummy struct that contains the previous node
T *listTraverse; // Dummy struct to check if there is a next node as we traverse
// Start at the beginning of the list
listTraverse = this;
if(listTraverse != 0)
{
while(listTraverse->next != 0)
{
previous = listTraverse;
listTraverse = listTraverse->next;
if(listTraverse->ID == ID)
return previous;
}
}
else
{
// Error, no root
}
}
template <class T>
T * cLinkedList <T>::ScanList(int ID)
{
// Dummy struct to check if there is a next node as we traverse
T *listTraverse;
// Start at the beginning of the list
listTraverse = this;
if(listTraverse != 0)
{
while(listTraverse->next != 0)
{
if(listTraverse->ID == ID)
return listTraverse;
listTraverse = listTraverse->next;
}
}
else
{
// Error, no root
}
}
template <class T>
T * cLinkedList <T>::ScanListEnd()
{
T *dummy;
if(this != 0)
{
dummy = this;
while(dummy->next != 0)
dummy = dummy->next;
}
else
{
// Error, no root
}
return dummy;
}
template class cLinkedList<cTile>;
template class cLinkedList<cEntity>;
template class cLinkedList<cLayer>;Edit: Gah, I always forget to leave out a crucial bit of information. cLayer, cTile, and cEntity all inherit cLinkedList. They all call the functions inherited by this->ScanList(ID), or equivalent.
So basically, what am I doing wrong? As always, all replies and help is very appreciated.






