-1

I'm trying to create an array of pointers for my hashtable. But I'm having trouble because I keep on getting segmentation faults for my functions(i.e. add, remove, find, delete functions) and I'm not sure if it's because I don't have my array of pointers declared and defined correctly. Here is what I have:

Node **array = new Node* is this how you would create a dynamic array of pointers?

programmingblues
  • 113
  • 2
  • 10
  • `Node ** array = new Node *[10];` – J3soon Dec 27 '15 at 04:29
  • 4
    Possible duplicate of [C++ Array Of Pointers](http://stackoverflow.com/questions/2879700/c-array-of-pointers) – joce Dec 27 '15 at 04:32
  • nope, I think he meant dynamic array of pointers... – J3soon Dec 27 '15 at 04:34
  • @J3soon yes exactly!! now is this how my private member variable would look: `Node **array;`? And my default constructor would be: `array = new Node*[size]`?? – programmingblues Dec 27 '15 at 04:59
  • I wouldn't use anything involving `*` or `new`, or custom destructors. And therefore I wouldn't have segmentation faults and other such memory errors. – M.M Dec 27 '15 at 06:02

1 Answers1

1

I think you can use :

Node **array = new Node*[10];

setting the pointer :

Node node;
array[0] = &node;

and remember to delete :

delete[] array;
J3soon
  • 3,013
  • 2
  • 29
  • 49