Lets say I have a program and a value like int finalValue = 1234;. Next there are pointers that point to finalValue. For Example:
int *p = &finalValue;
int **p2p = &p;
int ***p2p2p = &p2p;
If I wanted to create a function that ran down the pointer chain till it got to the finalValue (1234) what would be the most optimal way of doing it if the number of pointers too pointers can change.
The function would be given the first pointer in the chain (so in the above case p2p2p). General traversal would look like p2p2p -> p2p -> p -> finalvalue.
How do I do this for an unknown number of pointer in a chain (min 1, max of 5)
Initial prototyping brought me to using
foo(pointer) {
while (typeid(pointer).name() != "int") {
//do traversal through pointer chain
}
return pointer; //at this point it would have the value 1234
}
But I dont know how to properly traverse down the chain, or how to efficiently check and stop.
Any help is appreciated.