开发者

Problem in getting the first address of a 3 dimensional pointer into a single dimensional pointer?

can a single dimension array made to point to the first address of a three dimensional array, e.g. int *array; int ***array3D; array=*array3D; I need the first array to point to the first address of the second开发者_StackOverflow社区 array. I need only the first address into the pointer. Can anyone please suggest any alternatives to point to the starting address? Thanks in advance.


This kind of thing happens all the time when you're processing 2D and 3D images.

That you wrote (array = *array3D) obviously won't compile though because the types don't match. array3D is an **int and array is an *int.

If you have array3D set up correctly, as such (for example):

int ***array3D = new int **[zsize];
for(int z = 0 ; z < zsize ; ++z)     
{
    array3D[z] = new int *[ysize];
    for(int y = 0 ; y < ysize ; ++y)
    {  
         array3D[z][y] = new int [xsize];
    }
}

Then you can access things like array3D[z][y] (points to the x=0 element for the given z and y) or &(array3D[z][y][x]) (points to element x, y, z) or *(array3D[z]) (points to the y=0 and x=0 element for the given z), and will then all be of type int *. I suggest writing out how your data is organized.

Of course you have to manually delete this structure as well and if you're doing this in a product, you should be careful that you handle exceptions well and don't leak, but this another topic.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜