Array of Pointers to Structs
Every once in a while, I mean year, I need to create an Array of Pointers to Structs (at runtime - user defined size) and i can NEVER remember how to do it and my reference book example doesnt seem to help me too much. So, I made a test prog to do so yet it blows up on me at the end. What am i missing... this time?
Code:
#include <iostream>
using namespace std;
struct node
{
int n;
node * ptrnode;
node(){n = 0; ptrnode = NULL;}
};
class Obj
{
public:
Obj(){size = 0; root = NULL;}
Obj(int i)
{
size = i;
root->ptrnode = new node[i];
}
//private:
int size;
node * root;
};
int main()
{
int i;
cout<<"create number: ";
cin>> i;
Obj test(i);
cout << "Size is " << test.size;
return 0;
}