5

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);

1

6 Answers 6

10

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*>& (or vector<shared_ptr<T> >& not T***
Sign up to request clarification or add additional context in comments.

Comments

10

You could refer to a 3 dimensional array of ints as int *** intArray;

2 Comments

Hi! 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)); } }
Its allocating a 3d array of ints with dimensions nx, ny, nz.
4

Well, if your function needs to modify a pointer to a pointer ... ;)

See http://c2.com/cgi/wiki?ThreeStarProgrammer for a discussion.

Comments

2

Pointer to a dynamic array of pointers maybe? Make sense to me.

Comments

1

I think the root cause for this is thinking that "All the problems in the computer science can be solved by one more level of indirection." http://www.c2.com/cgi/wiki?OneMoreLevelOfIndirection

Added level of indirection are often necessary for invoking sub classes methods or directly accessing sub classes elements. And there is no such limit on having pointer to pointer to ...pointer to stuff.

Comments

0

I never go beyond 'pointer to pointer' - I think if you have to then something is fundamentally wrong with your design.

1 Comment

I think either DirectX or COM made me go three levels derp.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.