I wrote a template class which is giving compilation error
template
class Entity
{
string EntityName;
int EntitySize;
Entity
Alright. I'm explaining you the problem you're facing. But first thing first. You said:
I wrote a template class which is giving compilation error
First of all, as far as C++ is concerned, there is no such thing as a "template class," there is only a "class template." The way to read that phrase is "a template for a class," as opposed to a "function template," which is "a template for a function." Again: classes do not define templates, templates define classes (and functions).* Quoted from here.
Now, lets see the error:
fatal error C1202: recursive type or function dependency context too complex
The error says it all. $14.7.1
from the Standard explains the cause of your problem very well, giving you even an example which is very much close to what you're doing. So I don't even need to write a single word of my own. Here is $14.7.1
4 There is an implementation-defined quantity that specifies the limit on the total depth of recursive instantiations, which could involve more than one template. The result of an infinite recursion in instantiation is undefined. [ Example:
template < class T > class X { X
* p; // OK X a; //implicit generation of X requires //the implicit instantiation of X which requires //the implicit instantiation of X which ... }; —end example ]
Please read the comment with X
, which is pretty much the case with you too. So your problem is not because of recursive function, it's rather because of recursive instantiation of class template, causing from these lines:
Entity pPrev;
Entity pNext;
Hope, it solves your problem!
EDIT : But I'm wondering what are you trying to achieve with Entity
? It seems its a typo, and you probably wanted to write Entity
. Same with pNext
. Is that so?
And an advice to improve the design : Use Member Initialization list, instead of Assignment. That is, write your constructor the following way,
Entity(const string & name, int size) : EntityName(name), EntitySize(size)
{
//all assignments moved to initialization list.
}
Read this : Why should I prefer to use member initialization list?