-1
我在做這個工作嗎?我想要一個Integer作爲鍵的映射,並將struct作爲值。說我想要的對象是1
,最簡單的方法是什麼?我如何檢索isIncluded
的值?代碼中的最後兩行,我試過,但後來我意識到我不知道在編號的Map數組中檢索結構值的方式。C++數組中的結構
我是否需要調用cells.get(1)
並將其分配給新的臨時結構以獲取其值?
/** set ups cells map. with initial state of all cells and their info*/
void setExcludedCells (int dimension)
{
// Sets initial state for cells
cellInfo getCellInfo;
getCellInfo.isIncluded = false;
getCellInfo.north = 0;
getCellInfo.south = 0;
getCellInfo.west = 0;
getCellInfo.east = 0;
for (int i = 1; i <= (pow(dimension, 2)); i++)
{
cells.put(i, getCellInfo);
}
cout << "Cells map initialized. Set [" << + cells.size() << "] cells to excluded: " << endl;
cells.get(getCellInfo.isIncluded);
cells.get(1);
}
的地圖,被聲明爲像這樣的私人實例變量:
struct cellInfo {
bool isIncluded;
int north; // If value is 0, that direction is not applicable (border of grid).
int south;
int west;
int east;
};
Map<int, cellInfo> cells; // Keeps track over included /excluded cells
「cells」的聲明是什麼? –
你的意思是你想要一個'std :: map'結構嗎? –
tadman
它是一個私有實例變量:Map cells; –