For (1), what does line 2 do here?
1 2
|
for (int i = 0; i<size; i++)
blocks[i] = flavour;
|
Note that your
eat
does not check whether blockNumber is valid, nor whether that block is still uneaten. You do have a destructor, don't you?
Your smallbar has one row of
size
blocks. (A
const size
would be logical.)
A largebar probably should have multiple rows, each with [code]size[code] blocks. R rows times C columns makes R*C blocks. Therefore, a smallbar with size == R*C has equal number of blocks, but it has only one index (blockNumber).
A largebar would want to eat a block from (row Y, column X).
Sanity of eating from the middle of a bar is beyond us now. There are two obvious ways to 2D index:
1. Have a second array with pointers. Each pointer points to beginning of one row within a 1D array that holds all elements.
2. Compute the index. Block (X,Y) is the
(Y*columns + X)th block in the 1D array.
If you do choose to use the second way, then BigChocolate could be implemented by
having a SmallChocolate, rather than being a similar type.