又一个编译能过,但跑不起来的程序?解决方案

又一个编译能过,但跑不起来的程序?这是一个演示链表的程序(照书抄的),本来应该发到数据结构版的,不过由于

又一个编译能过,但跑不起来的程序?
这是一个演示链表的程序(照书抄的),本来应该发到数据结构版的,
不过由于根本跑不起来,所以发到这里了,而且数据结构的
操作也大都屏蔽了。请看代码:

//file:LinkList.h

#ifndef   LinkList_H
#define   LinkList_H
template   <class   T>
struct   Node
{
T   data;
Node <T>   *next;
};

//const   int   LEN=10;

template   <class   T>
class   LinkList
{
public:
LinkList(T   a[],int   n);
~LinkList();
void   Insert(int   i,T   x);
T   Delete(int   i);
int   Locate(T   x);
void   PrintList();
private:
Node <T>   *first;
};
#endif

---------------------------------


//file:LinkList.cpp

#include   "LinkList.h "
template   <class   T>
LinkList <T> ::LinkList(T   a[],int   n)
{
Node <T>   *first;
first=new   Node <T> ;//[]
first-> next=NULL;
for(int   i=0;i <n;i++)
{
Node <T>   *s;
s=new   Node <T> ;//[]
s-> data=a[i];
s-> next=first-> next;
first-> next=s;
}
}

template   <class   T>
LinkList <T> ::~LinkList()
{
Node <T>   *p,*q;
p=first;
while(p)
{
q=p;
p=p-> next;
delete   q;
}
}

template   <class   T>
void   LinkList <T> ::Insert(int   i,T   x)
{
Node <T>   *p;
int   j;
p=first;
j=0;
while(p   &&   j <i-1)
{
p=p-> next;
j++;
}
if(!p)
throw   "位置异常 ";
else
{
Node <T>   *s;
s=new   Node <T> ;
s-> data=x;
s-> next=p-> next;
p-> next=s;
}
}

template   <class   T>
T   LinkList <T> ::Delete(int   i)
{
Node <T>   *p;
int   j;
p=first;
j=0;
while(p&&j <i-1)
{
p=p-> next;
j++;
}
if(!p   ||   !p-> next)
throw   "位置 ";
else
{
Node <T>   *q;
int   x;
q=p-> next;
x=q-> data;
p-> next=q-> next;
delete   q;
return   x;
}
}

template   <class   T>
int   LinkList <T> ::Locate(T   x)
{
Node <T>   *p;
int   j;
p=first-> next;
j=1;
while(p   &&   p-> data!=x)
{
p=p-> next;
j++;
}
if(p)
return   j;
else
return   0;
}

template   <class   T>
void   LinkList <T> ::PrintList()
{
Node <T>   *p;
p=first-> next;
while(p)
{
cout < <p-> data < <endl;
p=p-> next;
}
}

----------------------------------


//file:main.cpp

#include   <iostream.h>
#include   "LinkList.cpp "
void   main()
{
int   r[]={1,2,3,4,5};
LinkList <int>   a(r,5);
cout < < "执行插入操作前数据为: " < <endl;


a.PrintList();
/*try
{
a.Insert(2,5);
}
catch(char   *s)
{
cout < <s < <endl;
}
cout < < "执行插入操作后数据为: " < <endl;
a.PrintList();
cout < < "值为5的元素位置为: " < <endl;
cout < <a.Locate(5) < <endl;
cout < < "执行删除操作前数据为: " < <endl;
a.PrintList();
try
{
a.Delete(1);
}
catch(char   *s)
{
cout < <s < <endl;
}
cout < < "执行删除操作后的数据为: " < <endl;
a.PrintList();
*/
}

---------------------------         the   end           ------------------------

[解决办法]
构造函数中定义了一个局部变量屏蔽了成员变量
建议删除构造函数体第一行的 Node <T> *first;