亦余gcx 2021-01-29 15:30 采纳率: 50%
浏览 122

不能将 "Queue::Node *" 类型的值分配到 "Queue::Node *" 类型的实体

尝试《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;
  • 写回答

1条回答 默认 最新

  • qq_29366533 2021-01-29 16:02
    关注

    使用memcpy赋值

    评论

报告相同问题?

悬赏问题

  • ¥20 云南省制造业对经济增长的影响目录应该怎么罗列,就是现状那部分
  • ¥15 绘制饼图及环形图(饼图和环形图示)
  • ¥15 求一套完整的纵横四海程序。
  • ¥15 python编写ros控制乌龟移动报错,如何解决?
  • ¥20 AD7606采集到电压乱飘,怎么解决呢
  • ¥60 有没有人查监控方面厉害的呢
  • ¥15 绑住完成C语言的任务
  • ¥20 vue项目打包Android apk,实现小说文本朗读功能
  • ¥50 IPv6网络,br-lan拿不到地址无法全局路由
  • ¥15 微信小程序分页查询如何设置下一页