Reputation: 61
I have a dynamic matrix in a class created by allocating memory in this way:
int **m; //this in the member head pointer
void allocate_mem(int ***ptr, unsigned r, unsigned c){
*ptr = new int *[r];
(*ptr)[0] = new int[r*c];
for(unsigned i = 1; i < r; i++)
(*ptr)[i] = (*ptr)[0] + i*c;
}
how can I call the pointers to the rows? I mean, m is the pointer to the array of pointers, *m is the pointer to the first row, but I don't know how to call the pointers to the other row
Upvotes: 0
Views: 583
Reputation: 21013
*m
is the pointer to the row with index 0 indeed, but *m
is equivalent to m[0]
. So for other indexes use m[index]
Upvotes: 3