I don't understand your explanation. Why do you say the pointer
arithmetic "wouldn't work"? Assuming x : int**,
x
+---+ +---+ +---+---+
| |---->| |---->| 5 | 7 |
+---+ +---+ +---+---+
| |
+---+
int** int* int
So,
x : int** returns the address of the 0th element of the first array.
x + i : int** returns the address of the ith element of the first array.
*(x + i) : int* returns the value of the ith element of the first array,
or the address of the 0th element in the second array.
*(x + i) + j : int* returns the address of the jth element in the second
array.
*(*(x + i) + j) : int returns the value of the jth element in the second
array.
Can you explain what I'm missing? I'm not asserting anything; I'm sure
there's a perfectly good reason why this casting is not allowed. I'm
just not seeing it.
As for my original question, I'm simply wondering how to do the
following:
int** asdf = new int[i][j];
You can't apply the approach you suggested because you don't know the
size of the array in at compile-time.
"John Harrison" <jo*************@hotmail.com> wrote in
news:2q************@uni-berlin.de:
"overbored" <ov*********@SPAMoverbored.net> wrote in message
news:Xn******************************@127.0.0.1...I can do this:
int asdf[2];
int* zxcv = asdf;
but not this:
int asdf[2][2];
int** zxcv = asdf;
or I get 'cannot convert from int[2][2] to int**'. Does anybody know
why this is, and how to get around it?
C++ says T[] converts to T*, it doesn't say anything about T[][] to
T** and why should it? It would be impossible to implement. T[]
converts to T* because x[i] is equivalent to *(x + i). But x[i][j] is
not equivalent to *(*(x + i) + j) because the pointer arithmetic
doesn't work.
I just want a pointer to that double
array. Thanks in advance.
Why? If you explain what you are trying to do then maybe someone can
tell you how.
You can do this
int asdf[2][2];
int (*zxcv)[2] = asdf;
Is that good enough?
john