Please take a look at the last function below :) :
#define IS_IDX_VALID(i, count) (0 <= i && i < count)
class CTest
{
enum { slotCount = 10, rowCount = 10, colCount = 20, invalidValue = INT_MIN };
int m_arValues[slotCount][rowCount][colCount];
void InitValues() {..}
public:
CTest() { InitValues(); }
int GetValue(int s, int r, int c) const
{
int iResult(invalidValue);
bool bValidParams(IS_IDX_VALID(s, slotCount) &&
IS_IDX_VALID(r, rowCount) &&
IS_IDX_VALID(c, colCount) &&);
ASSERT(bValidParams);
if (bValidParams) {
iResult = m_arValues[s][r][c];
}
return iResult;
}
int GetValue(int iAbsAddr) const
{
int iResult(invalidValue);
static int siSlotMaxCount(rowCount * colCount)
static int siAbsMax(slotCount * siSlotMaxCount);
ASSERT(IS_IDX_VALID(iAbsAddr, siAbsCount));
if (IS_IDX_VALID(iAbsAddr, siAbsCount)) {
int s = iAbsAddr / siSlotMaxCount,
t = iAbsAddr % siSlotMaxCount,
r = t / colCount,
c = t % colCount;
iResult = m_arValues[s][r][c];
}
return iResult;
}
};