This is a snippet from a larger block of code. The print statements are included for testing.
Within 'main', if I ouput the 'cell_ptr' or 'params' pointers, it correctly returns pointer values but if I try to output an element from the params array, I get an '...illegal operation...' message.
Yet it works OK in the sub.
What am I doing wrong?
struct keys {
string *params;
keys *next;
};
keys *cell_ptr = NULL;
void build_celldata()
{
keys *curr;
char buffer[5];
string cells[] = { "R0","" };
for (int i=0; i<5; i++)
{
sprintf(buffer, "%d", i);
string si = buffer;
cells[1] = "celldata" +si+ "0";
keys *temp = new keys;
temp->params = cells;
temp->next = NULL;
if (cell_ptr == NULL)
{
cell_ptr = temp;
curr = cell_ptr;
// testing
cout << cell_ptr->params[0] << "=" << cell_ptr->params[1] << endl;
}
else
{
curr->next = temp;
curr = curr->next;
//testing
cout << curr->params[0] << "=" << curr->params[1] << endl;
}
}
}
int main()
{
build_celldata();
//testing
cout << cell_ptr->params[0] << "=" << cell_ptr->params[1] << endl;
return 0;
}