Question: I'm having trouble in compiling the following code. The compiler states:

```
Assigning to 'RawChunk::Ptr' (aka 'unsigned char (*)[128][16]') from incompatible type 'RawChunk::Chunk *' (aka 'unsigned char (*)[16][128][16]');

```

Does anyone know what I'm doing wrong? It seems like a simple mistake but I'm not sure what I'm supposed to change.

```
template <int dim>
class RawChunkWindow {
public:
    typedef unsigned char (*Ptr)[ChunkDimensions::MAX_Y][ChunkDimensions::MAX_Z];
    typedef unsigned char Chunk[ChunkDimensions::MAX_X][ChunkDimensions::MAX_Y][ChunkDimensions::MAX_Z];
    RawChunkWindow() {
        for (int i = 0; i < dim; ++i) {
            for (int j = 0; j < dim; ++j) {
                window[i][j] = &payload[i][j]; //compiler complains here
            }
        }
    }
private:
    Ptr window[dim][dim];
    Chunk payload[dim][dim];
};

```

Answer: 
From your code snipped in the constructor of `RawChunkWindow`, it looks like your `Ptr` types should be pointers to `Chunk` types, but your `typedef` declarations don't reflect that. Instead `Ptr` is a pointer to a two-dimensional array of `char` types, not a pointer to a three-dimensional array.

So change this:

```
typedef unsigned char (*Ptr)[ChunkDimensions::MAX_Y][ChunkDimensions::MAX_Z];

```

to this:

```
typedef unsigned char (*Ptr)[ChunkDimensions::MAX_X][ChunkDimensions::MAX_Y][ChunkDimensions::MAX_Z];

```

This is also what your error code is reporting. A `unsigned char (*)[128][16]` is a pointer to a 128x16 two-dimensional array, and the compiler is complaining that you're attempting to assign a three-dimensional 16x128x16 array pointer rvalue (i.e., a `unsigned char (*)[16][128][16]` rvalue) to the wrong pointer-type.

As a side-node, be careful how you declare this object if you are planning on using them on the stack. A single `Chunk` type instance will take up 32Kb if the dimensions are 16x128x16, and a two-dimensional array of those could quickly eat up your stack-space if you pass too large a value as the template argument for `dim`.
To eliminate the error the way you currently have it, you need to change the line:

window[i][j] = &payload[i][j];

to

window[i][j] = &payload[i][j][x];

for some "x" less than "ChunkDimensions::MAX\_X". It's not clear to me what you're trying to do however, and the above fix almost certainly isn't it (probably). In simple terms, it appears that you may be trying to store a collection of 3D arrays in one collection (payload), and since a 3D array is really just an array of 2D arrays, you're then trying to store a pointer to each of these 2D arrays in another collection (window). I won't even get into the use of "dim" here, since the situation is already enough to twist one's head into a knot. In any case, using a "std::vector" instead of raw c-style arrays would be much easier. For a better understanding of the issues using c-style arrays in general (in case you can't use a "std::vector" for some reason), see my previous responses to [2Dimensional Array Pointer manipulation in C++](https://stackoverflow.com/questions/9583086/2dimensional-array-pointer-manipulation-in-c/9608139#9608139) and [manipulating multidimensional arrays with functions in C++](https://stackoverflow.com/questions/9672731/manipulating-multidimensional-arrays-with-functions-in-c/9677552#9677552). You can extend the concepts I present to 3D arrays.