我一直有很多麻煩,我的頭文件,並確保一切正確聲明。首先我的文件:錯誤:使用不完整的類型'struct Item'
//Main.cpp
#include "Item.h"
#include "Warehouse.h"
using namespace std;
int main() {
...
}
//Item.h
#ifndef ITEM_H
#define ITEM_H
#include <string>
using namespace std;
class Item {
...
};
#endif /* ITEM_H */
//Item.cpp
#include "Item.h"
//Warehouse.h
#define WAREHOUSE_H
#ifndef ITEM_H
#define ITEM_H
using namespace std;
class Item;
class Warehouse {
...
private:
Item* array; //problem starts with this
};
#endif /* WAREHOUSE_H */
//Warehouse.cpp
#include "Warehouse.h"
#include "Item.h"
Warehouse::Warehouse() {
array = new Item[arraySize]; //and this is where I get the error
}
我敢肯定這個問題與我的Warehouse.h頭,但每一個組合我儘量不工作要做。對不起,如果沒有足夠的代碼發佈,但我認爲問題是與包括和聲明。
提前致謝。
編輯:澄清這不是在一個文件中。我只是這樣寫的,以簡化事情。以上每一個都是一個單獨的文件。
你的包括警衛都搞砸了。 – juanchopanza
你在所有類的末尾都缺少分號。另外,它真的不是一個好主意,在標題內部使用'namespace'。 – Cameron
main()'last通常是一個好主意 –