Hi guys.
This time i want to ask something about generate 2D array using void pointer.
I've searched through this forum and i found this topic which is related to my problem.
http://www.cplusplus.com/forum/general/19209/
But. Although i've done the same way as him (the guy who's had the same problem as me in the forum above), the number won't come out.
The thing that came out was something like 'address' of the number.
m is a void***, so *(m + i) is a void**, *(*(m + i) + j) is a void*.
You need int, so you have to cast it to int* and then dereference: *((int*) *(*(m + i) + j))
// Type aliases
typedefvoid* element_t; // an element is a pointer to something
typedef element_t* column_t; // a list of elements is a column
typedef column_t* row_t; // a list of columns is a row
// Variables
unsigned number_of_rows;
unsigned number_of_columns;
row_t data;
...
// Initialize
data = new row_t[ number_of_rows ];
for (unsigned row = 0; row < number_of_rows; row++)
{
data[ row ] = new column_t[ number_of_columns ];
for (unsigned col = 0; col < number_of_columns; col++)
{
data[ row ][ col ] = (element_t)(newint);
}
}