If you want to point to nodes, then you need node pointers. You also seem to be undersizing your arrays by one.
Code:
Table[0] Table[1] Table[2]
=============================================
A[0] -- nodeA B[0] -- nodeG C[0] -- nodeK
A[1] -- nodeC B[1] -- nodeX C[1] -- nodeN
B[2] -- nodeM C[2] -- nodeP
B[3] -- nodeZ
struct node {
string name;
int value;
};
node *A, *B, *C;
node **Table;
Table = new node*[3];
Table[0] = A = new node[2];
Table[1] = B = new node[4];
Table[2] = C = new node[3];
And of course, you don't actually need A, B, and C. You could just assign the new memory directly to the Table elements.
EDIT: Another idea:
Code:
#include <iostream>
using namespace std;
struct Node {
int value; // got rid of string for simplicity
};
struct NodeArray {
int size;
Node *nodes;
};
void init(NodeArray &na, int sz) {
na.size = sz;
na.nodes = new Node[sz];
for (int i = 0; i < sz; i++)
na.nodes[i].value = i;
}
int main() {
NodeArray *Table = new NodeArray[3];
init(Table[0], 2);
init(Table[1], 4);
init(Table[2], 3);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < Table[i].size; j++)
cout << Table[i].nodes[j].value << ' ';
cout << '\n';
}
}