gpt4 book ai didi

c++ - 错误 : expected unqualified-id before ‘->’ token

转载 作者:行者123 更新时间:2023-11-30 04:27:27 24 4
gpt4 key购买 nike

第 21 行和第 22 行给我这个错误,这是我注意到的。从其他有类似错误信息的情况来看,我在某处遇到了语法错误。我就是想不通是什么。这是我的 .cpp 文件:

#include <iostream>
#include <cstdlib>

#include "deque.h"

using namespace std;

struct node{
int data;
node *prev;
node *next;
};

Deque::Deque(){
count = 0;

node->head->next = node->head; //error on this line
node->head->prev = node->head; //and this one
}

这是我的头文件:

# ifndef DEQUE_H
# define DEQUE_H


class Deque
{
private:
int count;
class node *head;
public:
Deque();
~Deque();
int size();
void addFirst(int);
void addLast(int);
int removeFirst();
int removeLast();
int getFirst();
int getLast();

};
#endif

最佳答案

这些行的正确代码:

head->next = head;
head->prev = head;

你的变量名为headnode是它的类型,但是你的类Deque中没有名为node的成员

关于c++ - 错误 : expected unqualified-id before ‘->’ token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10906835/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com