2016-11-14 72 views
-5

今天,我遇到了一個非常非常奇怪的問題。那是我的IDE始終無法識別包含last的最後一個類。我正在使用Qt Creator.My包括遵循:最後一個頭文件錯誤:C2065:'xxx':未聲明的標識符

#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會compain 「ForkliftItem未聲明的標識符」。我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 
+0

https://en.wikipedia.org/wiki/Include_guard – user4581301

回答

3

在這兩個文件中,都包含具有相同名稱的警衛 - CHARGINGSTATIONITEM_H。所以,在第一個文件中,它定義了CHARGINGSTATIONITEM_H,而在第二個文件中忽略了所有內容。

+0

是的,雖然我不知道爲什麼兩個宏生成的IDE都是相同的。 –

相關問題