最后一个头文件错误:C2065:' xxx' :未声明的标识符

时间:2016-11-14 16:08:52

标签: c++ qt include

今天,我遇到了一个非常奇怪的问题。那我的IDE始终无法识别我最后包含的最后一个课程。我正在使用Qt Creator.My包括如下:

#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抱怨&#34; ChargingStationItem 未声明的标识符&#34;。 如果我将 forkliftitem.h chargingstationitem.h 交换,IDE将会获得&#34; ForkliftItem 未声明的标识符&#34;。我 forkliftitem.h 如下:

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

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

#endif // CHARGINGSTATIONITEM_H

和chargingstationitem.h:

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

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

#endif // CHARGINGSTATIONITEM_H

1 个答案:

答案 0 :(得分:3)

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