Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pointer to Pointer to Pointer [duplicate]

Tags:

c++

pointers

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

like image 471
RoR Avatar asked Jan 11 '11 09:01

RoR


2 Answers

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

like image 143
Sam Dufel Avatar answered Oct 04 '22 00:10

Sam Dufel


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***
like image 43
CashCow Avatar answered Oct 04 '22 01:10

CashCow