qq_38397675 2017-04-20 03:22
浏览 533

为什么在派生类中基类定义的head tail 没用了 新人求解

#include
#include
using namespace std;
template
struct Node{
T data;
Node*prior;
Node*next;
};
template
class list{
public:
Node*head;
Node*tail;
list()
{
head=tail=NULL;
}
virtual void store(T i)=0;
virtual T retrieve()=0;
};

template
class queue:public list{
public:
void store(T i);
T retrieve();
};

template
void queue::store(T i)
{
Node*item;
item=new Node;
if(!item)
{
cout<<"error"< }
item->data=i;
if(!head)
{
item->prior=head;
head=tail=item;
item->next=NULL;
}
item->prior=tail;
tail->next=item;
tail=item;
item->next=NULL;
}

template
T queue::retrieve()
{
T temp;
Node*p;
if(!head)
{
cout<<"队列已空"< }
temp=head->data;
p=head;
head=head->next;
head->prior=NULL;
delete p;
return temp;

}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 用C语言输入方程怎么
    • ¥15 网站显示不安全连接问题
    • ¥15 github训练的模型参数无法下载
    • ¥15 51单片机显示器问题
    • ¥20 关于#qt#的问题:Qt代码的移植问题
    • ¥50 求图像处理的matlab方案
    • ¥50 winform中使用edge的Kiosk模式
    • ¥15 关于#python#的问题:功能监听网页
    • ¥15 怎么让wx群机器人发送音乐
    • ¥15 fesafe材料库问题