追加悬赏分“继承 c++ 链表”查错

来源:百度知道 编辑:UC知道 时间:2024/06/04 23:39:45
抽象链表类abslist,它有派生类List

追加悬赏分

我的程序已经废了
(不用仔细看)

#include<iostream>

using namespace std;

template <class type>
class ListNode
{
type data;
ListNode <type> *pNext;
public:
type& getData(){return data;};
void setData(type& newData){data=newData;};
ListNode(){pNext=NULL;}
ListNode(type value,ListNode<type> *p){
data=value;
pNext=p;
};
};

template <class type>
class abslist
{
protected:
ListNode <type> *pHead;
ListNode <type> *pCurrent;
ListNode <type> *pTail;
int length;
public:

type &Get(int Loc);
bool Set(type &x,int Loc);
v

直接用pCurrent可以。
main正确。
你看我下面的,编译没问题了,自己实现完函数就可以链接了。
#include<iostream>

using namespace std;

template <class type>
class ListNode
{
public:
type data;
ListNode <type> *pNext;
public:
type& getData(){return data;};
void setData(type& newData){data=newData;};
ListNode(){pNext=NULL;}
ListNode(type value,ListNode<type> *p){
data=value;
pNext=p;
};
};

template <class type>
class abslist
{
protected:
ListNode <type> *pHead;
ListNode <type> *pCurrent;
ListNode <type> *pTail;
int length;
public:

type &Get(int Loc);
bool Set(type &x,int Loc);
void MakeEmpty();

ListNode <type> &getNextData();

void setCurNext(){pCurrent=pCurrent->pNext;};
void setCurHead(){pCurrent=pHead;};

ListNode <type> *Fin