报错:参见对正在编译的类 模板 实例化“LinkList<Telem>”的引用,什么意思?
#include<iostream>using namespace std;
template<class Telem>
struct Tnode
{
Telem data;
Tnode * next;
};
template<class Telem>struct LinkList;
template<class Telem>class Node
{
Telem data;
Node<Telem>*next;
public:
Node(Telem d = 0,Node<Telem> *n=NULL*n=NULL):data(d),next(n){};
Telem getdata()
{
return data;
}
void setdata(Telem& el)
{
data=el;
}
Node<Telem> *getnext()
{
return next;
}
void setnext(Node<Telem> *p){next=p;}
};
template<class Telem>
struct LinkList
{
Node<Telem> *head;
int size;
Linklist(){head = new Node<Telem>();size=0;};
LinkList(Telem a[],int n);
void clear()
{
delete[]head;head= new Node<Telem>();size=0;
};
bool full()
{
return false;
};
bool empty()
{
return head->next === NULL;
};
int leng()
{
return size;
};
bool inst(int loc,Telem& el);
Telem delet(int i);
Node<Telem> * index(int i);
Telem gete(int i);
};//这里是VS2012的错误箭头指地方
template<class Telem>LinkList<Telem>::LinkList(Telem a[],int n)
{
Node<Telem> *p;
int i;
head =new Node<Telem>(0,NULL);
for(i=n-1;i>=0;i--)
{
p=new Node<Telem>(a[i],head->next);
head->setnext(p);
};
size=n;
};
template<class Telem>Telem LinkList<Telem>::delet(int i)
{
if(size==0)
return NULL;
Node<Telem> *p=index(i-1);
Telem el=p->next->getdata();
p->setnext(p->next->next);
size--;
return el;
};
template<class Telem>Telem LinkList<Telem>::gete(int i)
{
Node<Telem> * p=index(i);
return p->getdata();
};
int main()
{
char b[]={'a'};
LinkList<char>a1(b,1);
a1.clear();
cout<<a1.gete(1);
return 0;
}