Pointer to Pointer to Pointer
Solution 1
It is rare in C++ certainly.
In C it may well show up where:
- You use "objects" which are structs, and you always pass them around or create them on the heap as pointers.
- You have collections of such pointers as dynamically allocated arrays thus T** where T is the type.
- You want to get an array so you pass in a T*** and it populates your pointer with a T** (array of T* pointers).
This would be valid C but in C++:
- The first step would be the same. You still allocate the objects on the heap and have pointers to them.
- The second part would vary as you would use vector and not arrays.
- The 3rd part would vary as you would use a reference not a pointer. Thus you would get the vector by passing in
vector<T*>&
(orvector<shared_ptr<T> >&
not T***
Solution 2
You could refer to a 3 dimensional array of ints as int *** intArray;
Solution 3
Well, if your function needs to modify a pointer to a pointer ... ;)
See http://c2.com/cgi/wiki?ThreeStarProgrammer for a discussion.
Solution 4
Pointer to a dynamic array of pointers maybe? Make sense to me.
RoR
Updated on September 02, 2022Comments
-
RoR over 1 year
Possible Duplicate:
Uses for multiple levels of pointer dereferences?I was reading another post and this led me to this question. What the heck would something like this mean? Also how deep do people go with a pointer to a pointer to a pointer to a pointer.... I understand Pointer to Pointer but why else you would go more after that? how deep have you gone in using ****?
Foo(SomePtr*** hello);
-
TOMKA over 13 yearsI think either DirectX or COM made me go three levels derp.
-
secluded almost 8 yearsHi! Could you please elaborate on what you mean by this?? This is the piece of code I have and I don't understand what's happening:
int ***grid;
grid = calloc(nx,sizeof(int**));
for (i = 0; i < nx; ++i) { grid[i] = calloc(ny,sizeof(int*)); for (j = 0; j < ny; ++j) { grid[i][j] = calloc(nz,sizeof(int)); } } -
Sam Dufel almost 8 yearsIts allocating a 3d array of ints with dimensions nx, ny, nz.