Array of pointers to point to another array of pointers
Hello, I'm having some difficulties getting an Array of pointers to point to another array of pointers.
for example, I would like to have a "Table" that can point to various other arrays, these arrays, in turn, will point to some nodes.
* I know this is similar to a 2D array but not all the arrays from the table will be the same size.
a visual example:
Table[0] |
Table[1] |
Table[2] |
Ary[0] -- nodeA Bry[0] -- nodeG Cry[0] -- nodeK
Ary[1] -- nodeC Bry[1] -- nodeX Cry[1] -- nodeN
Bry[2] -- nodeM Cry[2] -- nodeP
Bry[3] -- nodeZ
The code would be something like
Code:
struct node{
string name;
int value;
};
int** Table;
int* Ary;
int* Bry;
int* Cry;
//Someplace in a function
void myFunction(){
Table = new int* [2];
Ary = new int[1];
Bry = new int [3];
Cry = new int [2];
Table[0] = Ary;
Table[1] = Bry;
Table[2] = Cry;
Ary[0] = newNode(); // make a new node function for the struct
Ary[1] = newNode(); // etc....etc.. for Bry and Cry
}
or would that not work since int* would only be able to take an integer value?
what if I did
Code:
int** Table;
int** Ary;
int** Bry;
int** Cry;
Another way of looking at it would be:
Search my Library(Table) for book A(Ary)
in Book A look for page 12(Node A).
Thank you