Click to See Complete Forum and Search --> : Template-type in template class!!


709394
04-19-2003, 08:14 PM
I try to create a link list that hold at each of its node another link list using template. But it doesn't work and I found out that template class can't be used as a template-type. Does someone know a workaround?
To demonstrate what I mean, here is the empty code :

This code doesn't work but this is what I want to do.

#include <iostream.h>

template <class T>
class LinkList
{
public:
LinkList(){};

};

int main(void)
{
LinkList<LinkList> LL;
return 0;
}


Code that works without using template class as template-type.

#include <iostream.h>

template <class T>
class LinkList
{
public:
LinkList(){};

};

class LinkListNotemplate // EXACTLY the same implemention of LinkList class above.
{
public:
LinkListNotemplate(){};
};

int main(void)
{
LinkList<LinkListNotemplate> LL;
return 0;
}


If I HAVE TO CODE the second way, then what is the POINT of template then?

bwkaz
04-19-2003, 10:46 PM
Originally posted by 709394
LinkList<LinkList> LL; Why are you making a linked list of linked lists of nothing? Shouldn't this be LinkList<int>, to make a linked list of integers, or something similar to that?

If you want a linked list of linked lists, then you have to tell it what you want each individual list to contain, like:

LinkList<LinkList<int> > LL; or something like that. If the inner templat isn't instantiated, the compiler chokes.

709394
04-19-2003, 11:13 PM
Thank!