I am trying to learn C++ and trying to write a code for a simple hash table like following structure:
array[0][0] array[0][1] array[0][2]
key 1 value 1 value 2
array[1][0] array[1][1]
key 2 value 3
array[2][0] array[2][1] array[2][2]
key 3 value 4 value 5
means Array of Dynamic Arrays. Now, I can’t understand how to define the array like that ?
Any help on this will be grateful.
If you really did need to create a dynamic array of dynamic arrays you would have to do it using the
newkeyword for both arrays. For example:Of course I highly recommend NOT doing this. You have to then remember to use
delete[]on each member ofarraysand onarraysitself.Really you should use the built in
std::vectortype for this. It is why it is there (I voted for the other answers!).Just as a note, this is not contiguous memory either. Also if you do want the member arrays to be the same size you could allocate their memory in a
forloop.