用模板实现链表的插入问题,提示三个错误! 请指教!!!!
#include<iostream>
using namespace std;
template <class T>
class LList
{
protected:
struct Node
{
T Data; // error C2079: “LList<T>::Node::Data”使用未定义的 class“T”
Node * Next;
} ;
Node * first;
int NumberNodes;
public:
LList(){ NumberNodes=0; Node * first=NULL;}
~LList();
int Length();
void Insertfirst(T el);
};
LList <class T>::~LList()
{
if( first!=NULL)
{
delete first;
first=NULL;
}
NumberNodes=0;
}
int LList <class T>::Length()
{
return NumberNodes;
}
void LList <class T>::Insertfirst(T e)
{
Node* newnode=new Node;
newnode->Data=e; // error C2440: “=” : 无法从“T”转换为“int”
if(NumberNodes==0)
first->Data=e; // error C2440: “=” : 无法从“T”转换为“int”
else
newnode->Next=first->Next;
first->Next=newnode;
NumberNodes++;
}
int main()
{
LList<int> L;
L.Insertfirst(2);
L.Insertfirst(3);
L.Length();
getchar();
return 0;
}
我感觉很可能是类内嵌套了结构,所以结构了面的T编译器不能识别,请问怎么解决!!!!!!