2012-11-08 411 views
-3

我必須實現一個程序,其中我有一個穩定大小的數組,並且進入每個單元格,我必須放置一個id,一個計數器和一個指針。我的問題是我如何將多個元素放入1個數組單元格?將多個元素放入1個數組單元格中?

+0

結構或類的數組? –

+0

嗨,歡迎來到SO--幫助做家庭作業的網站,而不需要付出一些努力 - 不!至少顯示你到目前爲止所嘗試的和/或爲什麼/不工作...請看看:http://stackoverflow.com/faq#questions –

回答

1

像這樣:

struct Cell { 
    Cell() : id(0), counter(0), pointer() {} 
    int id, counter; 
    std::unique_ptr<int> pointer; 
}; 

Cell cells[100]; 

您可以訪問這樣的內容:

cells[0].id = 1; 
++cells[0].counter; 
cells[0].pointer.reset(new int(9)); 
+0

我把這段代碼放在.h文件 struct entry { int counter,page_id; // AvlTree *指針; }; entry a [1000000]; and this piece if code at .cpp file SortedArray :: SortedArray(){ a-> page_id = 0; a-> counter = 0; // a-> pointer = NULL; } 我認爲它與你的code.right一樣嗎? – user1807955

相關問題