Anonymus Anonymus - 1 month ago 13
C++ Question

Deleting Value From Multi Dimensional Map?

I am currently making my own voxel engine in c++, however I seem to have come across a problem.

I am using a chunk based system and storing it in a 3-dimensional map, the variable definition looks like this:

map<uint64_t,map<uint64_t,map<uint64_t,Chunk*>>> Chunks;


However, I can't really find a proper way to delete any value from the map, I have tried using the
map::erase
function but with no succes, is there any good way to do this that I am unaware of?

P:S
This was the
map::erase
function I was trying:

Chunks[x][y].erase(z);


Thanks in advance!

Answer

The map is a key-value type, so you cannot try access as array:

Try to remove the first element by example:

Chunks.erase(KeyOfFirstElement);

from: http://www.cplusplus.com/reference/map/map/erase/