Why is my implementation of C++ map not storing values? <p>I have a class called ImageMatrix, which implements the C++ map in a recursive fashion; the end result is that I have a 3 dimensional array.</p> <pre><code>typedef uint32_t VUInt32; typedef int32_t VInt32; class ImageMatrix { public: ImageMatrixRow operator[](VInt32 rowIndex) private: ImageMatrixRowMap rows; }; typedef std::map &lt;VUInt32, VInt32&gt; ImageMatrixChannelMap; class ImageMatrixColumn { public: VInt32 &amp;operator[](VUInt32 channelIndex); private: ImageMatrixChannelMap channels; }; typedef std::map&lt;VUInt32, ImageMatrixColumn&gt; ImageMatrixColumnMap; class ImageMatrixRow { public: ImageMatrixColumn operator[](VUInt32 columnIndex); private: ImageMatrixColumnMap columns; }; typedef std::map&lt;VUInt32, ImageMatrixRow&gt; ImageMatrixRowMap; </code></pre> <p>Each operator simply returns a map-wrapper class within, like so:</p> <pre><code>ImageMatrixRow ImageMatrix::operator[](VInt32 rowIndex) { return rows[rowIndex]; } ImageMatrixColumn ImageMatrixRow::operator[](VUInt32 columnIndex) { return columns[columnIndex]; } VInt32 &amp;ImageMatrixColumn::operator[](VUInt32 channelIndex) { return channels[channelIndex]; } </code></pre> <p>Basically, when I set the value as say 100, and test the value to cout, it shows as 0, and not the number to which I had set it.</p> <pre><code>for (VUInt32 a = 0; a &lt; GetRowCount(); a++) { for (VUInt32 b = 0; b &lt; GetColumnCount(); b++) { for (VUInt32 c = 0; c &lt; GetChannelCount(); c++) { VInt32 value = 100; matrix[a][b][c] = value; VInt32 test = matrix[a][b][c]; // pixel = 100, test = 0 - why? cout &lt;&lt; pixel &lt;&lt; "/" &lt;&lt; test &lt;&lt; endl; } } } </code></pre> <p>Note: I've altered the original code for this example so that it takes up less space, so some syntax errors may occur (please don't point them out).</p>