0

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

1
  • 1
    ooh three-star programmer ... anyway, try a std::vector for the storage. Commented Jan 26, 2014 at 17:04

1 Answer 1

3

*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]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.