I have a structure usually containing a pointer to an int
. However, in some special cases, it is necessary that this int pointer points to another pointer which then points to an int. Wow: I mentioned the word pointer 5 times so far!
- Is this even possible?
I thought about it that way: Instead of using a second int pointer, which is most likely not possible as my main int pointer can only point to an int and not to another int pointer, I could make it a reference like this:
int intA = 1;
int intB = 2;
int& intC = intB;
int* myPointers[ 123 ];
myPointers[ 0 ] = &intA;
myPointers[ 1 ] = &intB;
myPointers[ 3 ] = &intC;
So the above would do what I want: The reference to intB
(intC
) behaves quite like I want it to (If it gets changed it also changes intB
)
- The problem: I can't change references once they are set, right? Or is there a way?
Everything in short: How do I get a value to work with *
(pointers) and **
(pointers to pointers)?