Pointer to pointer to pointer

Possible duplicate:
Used for several levels of pointer markup?

I read another entry, and this led me to this question. What the hell does something like this mean? Also, how deeply do people go with a pointer to a pointer to a pointer to a pointer .... I understand a pointer to a pointer, but why else could you go further after that? how deep did you use ****?

Foo (SomePtr *** hello);

+4
source share
6 answers

This is rare in C ++.

In C, it can appear where:

  • You use “objects”, which are structures, and you always pass them or create them on the heap as pointers.
  • You have collections of pointers such as dynamically allocated arrays, so T **, where T is a type.
  • You want to get an array to pass T ***, and it fills your pointer T ** (array of pointers T *).

This will be valid C, but in C ++:

  • The first step will be the same. You still allocate objects on the heap and have pointers to them.
  • The second part will be different since you will use vector rather than arrays.
  • The third part will be different because you are using a link, not a pointer. So you get the vector by going to vector<T*>& (or vector<shared_ptr<T> >& not T ***
+7
source

You can refer to the 3-dimensional array of ints as int *** intArray;

+10
source

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

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

+4
source

Could there be a pointer to a dynamic array of pointers? Make sense to me.

+2
source

I never go beyond the "pointer to pointer" - I think if you need something, something is fundamentally wrong with your design.

0
source

I think the main reason for this is that "all problems in computer science can be solved by another level of indirection." http://www.c2.com/cgi/wiki?OneMoreLevelOfIndirection

The added level of indirection is often necessary to invoke subclass methods or directly access subclass elements. And there is no such restriction on a pointer to a pointer to ... a pointer to a material.

0
source

Source: https://habr.com/ru/post/1335053/


All Articles