2013-11-28 22 views
2

編輯:看起來問題是過度使用#包括創建圈子。我確保只包含那些需要的東西,它解決了前兩個錯誤。陣列的大小超過了,但是數組很小

不過,我還是得到了兩個按鈕,電梯

它有兩個每個錯誤的「指定多個默認構造函數」,但兩者在同一地點對點,結束};的類。

編輯:第二個錯誤也解決了。我刪除了空的Class :: Class();沒有被使用。

==================================== 我得到一個錯誤「錯誤C2148 :數組的總大小不能超過0x7fffffff字節

無論類或數組的大小如何,我的類定義中的第一行都會產生這個錯誤。「Elevator elevators [1];」will give儘管Elevator對象只有70字節左右,但即使它們非常大,它也不會停止在整數,字符串等數組上,即使它們非常大也不會停止。爲此。

class Passenger; 
class Simulation{ 
    int test[10000];<-- no error 
    std::queues<int> q[10];<--- no error 
    Elevator e[1];<--- size error, but size of one Elevator is only 70 bytes 
} 

在這個錯誤之下,它還說「模擬:電梯使用未定義的類電梯」,但我 有上面初始化。我也有passenger.h #included。我最初使用的是載體,但實際上會導致更多的問題,而且我並不需要它們,因爲大小是恆定的。

進一步的測試顯示我的一個對象(Report)沒有給出錯誤,但是它涉及多個向量。

編輯(實際上它提供了兩個電梯和按鈕的錯誤,無論在代碼中他們

編輯:添加通力電梯定義爲每個請求:

class Elevator{ 
private: 
    int floor; 
    int floorGoal; 
    int answering; 
    int floorIdle; 
    bool goingUp; 
    int mode; 
    int nextMode; 
    int nextModeTime; 
    int numPassengers; 
    static const int maxPassengers = 8; 
    int passengers[maxPassengers]; 
    static const int moveTime = 15; 
    static const int boardTime = 3; 
    static const int leaveTime = 3; 
    static const int delayTime = 10; 
public: 
    Elevator(); 
    Elevator(int Floor = 1); 
    ~Elevator(); 
    bool IsFull() const; 
    bool IsEmpty() const; 
    void Update(int timeElapsed, int i, PassengerGenerator& gen, Report& r, Button b[], Elevator e[], std::queue<int> q[]); 
    friend class Simulation; 
}; 

此外,包括按鈕,因爲它具有相同的錯誤,但要簡單得多

class Button{ 
private: 
    int answered; 
    bool pressed; 
    bool up; 
public: 
    Button(); 
    Button(int Floor = 1, bool Up = true); 
    ~Button(); 
    inline bool IsCalling() const{ return pressed && answered == -1;} 
    friend class Elevator; 
    friend class Simulation; 
}; 

當我這樣做,我注意到另一個錯誤越往下列表。它說「多defau爲電梯和按鈕指定'構造函數'。不過,我證實,都只有只有一個不帶參數)construtor,對於定義爲格式類::類({}

+3

電梯類型定義請。 – ScarletAmaranth

+0

什麼平臺和編譯器? –

+0

我猜這個問題實際上是一個未定義的類的使用。請包括電梯的定義,以及它相對於班級的位置。模擬 – JSQuareD

回答

1

必須定義類型Elevator之前,你可以用它來申報數據成員e。你已經聲明瞭這個類型,但是你沒有定義它。

第一個錯誤是有些誤導,但第二個錯誤是很清楚的:

error C2148: total size of array must not exceed 0x7fffffff bytes 
error C2079: 'Simulation::e' uses undefined class 'Elevator' 
+0

它在#class「elevator.h」和一個班級電梯兩者之上,還需要定義什麼? – user3046916

+0

你可能在你的頭文件之間有循環依賴關係。 Elevator.h #include包括直接或間接#包含您的Simulation類定義的源文件的任何內容嗎? –

+0

我剝去了不必要的包含,它修復了前兩個錯誤,所以謝謝。 雖然 – user3046916