【问题标题】:The last header file error: C2065: 'xxx' : undeclared identifier最后一个头文件错误:C2065: 'xxx' : undeclared identifier
【发布时间】:2016-11-14 16:08:52
【问题描述】:

今天遇到一个很奇怪的问题,就是我的IDE总是不能识别我最后包含的最后一个类。我用的是Qt Creator,我的包含如下:

#include "realtimemonitor.h"
#include "ui_realtimemonitor.h"

#include <QGraphicsView>
#include <QGraphicsScene>
#include <QHBoxLayout>
#include "forkliftinfo.h"
#include <thread>
#include "goodsitem.h"
#include "goodslocationitem.h"
#include "forkliftitem.h"
#include "chargingstationitem.h"

此时,IDE 报错“ChargingStationItem 未声明的标识符”。 如果我将 forkliftitem.hchargingstationitem.h 交换,IDE 将包含“ForkliftItem 未声明的标识符”。我的 forkliftitem.h强>如下:

//forkliftitem.h
#ifndef CHARGINGSTATIONITEM_H
#define CHARGINGSTATIONITEM_H
#include <QGraphicsItem>

class ForkliftItem : public QGraphicsItem  { public:
    ForkliftItem();
    };

#endif // CHARGINGSTATIONITEM_H

还有chargestationitem.h:

//chargingstationitem.h
#ifndef CHARGINGSTATIONITEM_H
#define CHARGINGSTATIONITEM_H
#include <QGraphicsItem> 

class ChargingStationItem : public QGraphicsItem  { public:
    ChargingStationItem();
    };

#endif // CHARGINGSTATIONITEM_H

【问题讨论】:

  • 由 Crawl.W 于 2016 年 11 月 14 日 16:08 提出这不是一个无意义的问题,只是不太常见。无论是粗心还是编辑器错误,这个问题在这些时候都会有所帮助。采纳的答案是投票的 3 倍,足以表明他的贡献。

标签: c++ qt include


【解决方案1】:

在这两个文件中,您都包含同名的守卫 - CHARGINGSTATIONITEM_H。因此,在第一个文件中,它定义了 CHARGINGSTATIONITEM_H,而在第二个文件中则忽略了所有内容。

【讨论】:

    猜你喜欢
    • 2022-06-11
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多