henhen
henhen

Reputation: 1205

what is this dynamic object creation * []

What does this mean? The following is a snippet from here

class HashTableEntry {
   public:
      int k;
      int v;
      HashTableEntry(int k, int v) {
         this->k= k;
         this->v = v;
      }
};
class HashMapTable {
   private:
      HashTableEntry **t;
   public:
      HashMapTable() {
         t = new HashTableEntry * [T_S]; //What does this do
         for (int i = 0; i< T_S; i++) {
            t[i] = NULL;
         }
      }

In this code, t is a double pointer and it is assigned to new HashTableEntry * [T_S]

Does new HashTableEntry * [T_S] mean the Object HashTableEntry is being made into a pointer to point to an array with size of T_S?

If it is, I am not understanding how a dynamically created object with the new HashTableEntry is being delcared as an [T_S] when the definition of HashTableEntry is clearly a class/struct

Upvotes: 1

Views: 61

Answers (1)

smac89
smac89

Reputation: 43206

t = new HashTableEntry * [T_S]

This creates an array of pointers to HashTableEntry. It creates T_S counts of them.

Perhaps it is clearer if written like this:

using HTEntry = HashTableEntry*;
t = new HTEntry [T_S];

Upvotes: 3

Related Questions