0
table = new myObject*[TABLE_SIZE];

I know that * are for declaring pointers variable and to obtain the value of the variable from a pointer, but what does this mean?

Andrea De Luca
  • 127
  • 1
  • 8
  • Note that this is typically bad C++ style. A better solution would be `std::vector table(TABLE_SIZE, nullptr)`. But I suspect there are more problems, such as the use of non-smart pointers and possible a ` #define TABLE_SIZE`. – MSalters Nov 08 '16 at 11:11

4 Answers4

2

It means exactly that.

table is a pointer to an array (with size TABLE_SIZE) of pointers to objects of type myObject. Note that you haven't allocated any memory for those pointers at this point.

Don't forget to call delete[] table; once you're done with it.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
1

This means that you allocate an array of type myObject* of size TABLE_SIZE.

So in this case we allocate space for the pointers but not the objects.

Your variable table will then be a pointer to an array of pointers, or a myObject**.

So table will point to the first element in this list of pointers.

Tommy Andersen
  • 7,165
  • 1
  • 31
  • 50
0

The asterisk means pointer here too. I am assuming that table is declared like

myObject** table;

What you are doing is allocating an "array" of TABLE_SIZE pointers to myObject.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
0

It means exactly what you already know it means :-)

The type myObject * is a pointer to a myObject object so what you are declaring is an array of said pointers, TABLE_SIZE of them to be exact.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953