我从C ++开始,我无法弄清楚。我有三个类,正在尝试实现一个队列。 (不管现在是否正常,我只需要修复此错误)

#include <cstdlib>
#include <iostream>
#include "queue.h"

using namespace std;

int main(int argc, char** argv) {

    queue fronta();

    queue.add(10); // <- expected unqualified-id before ‘.’ token
}


queue.h:

#ifndef QUEUE_H
#define QUEUE_H

#include "queueItem.h"

class queue {
private:
    queueItem* first;
    queueItem* last;

public:
    queue();
    void add(int number);
    int get(void);
    bool isEmpty();
};

#endif  /* QUEUE_H */


queueItem.h:

#ifndef QUEUEITEM_H
#define QUEUEITEM_H

class queueItem{
private:
    int value;
    queueItem* next;

public:
    queueItem(int value);

    int getValue();
    queueItem* getNext();
    void setNext(queueItem* next);
};

#endif  /* QUEUEITEM_H */


根据我搜索过的内容,它通常与多余的分号,方括号等有关。我什么也没找到

感谢帮助

最佳答案

您不能在类类型.add()上调用queue,需要在已创建的对象上调用它!您的情况是fronta.add(10);

另外,您创建fronta的语法是错误的。使用queue fronta;

关于c++ - token 错误前的预期unqualified-id,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14923049/

10-15 04:50