尝试《c++ primer plus第六版》383-384页。
文件queue.h
#ifndef Queue_H_
#define Queue_H_
class Customer
{
private:
long arrive;
int processtime;
public:
Customer(){ arrive = processtime = 0;}
void set(long when);
long when() const { return arrive;}
int processtime() const { return processtime;}
};
typedef Customer Item;
class Queue
{
private:
struct Node
{
Item item;
struct Node * next;
};
enum { Q_size=10 };
Node * front;
Node * rear;
int items;
const int qsize;
Queue(const Queue & q) : qsize(0) {} // 复制构造函数
Queue & operator=(const Queue & q) { return *this;} // 执行深度复制的赋值运算符
public:
Queue(int qs = Q_size); // 默认队中放10个
~Queue();
bool isempty() const;
bool isfull() const;
int queuecount() const; // 队中有几个
bool enqueue(const Item & item); // 入队
bool dequeue(Item & item); // 出队
};
#endif
文件queue.cpp
#include "queue.h"
#include <cstdlib>
Queue::Queue(int qs) : qsize(qs)
{
front = rear = nullptr;
items = 0;
}
Queue::~Queue()
{
Node * temp;
while (front != nullptr)
{
temp = front; // 这里报错。
front = front->next;
delete temp;
}
}
报错:不能将 "Queue::Node *" 类型的值分配到 "Queue::Node *" 类型的实体
尝试百度,无果
尝试修改链表定义,改成这样,依旧没用
typedef struct Node
{
Item item;
struct Node * next;
}Node;