I've been studying a bit on hash tables and how to create them with chaining in C++. In an example of code I found, the list and buckets are declared as follows:
int bucket;
std::list<int> *table;
Then, elsewhere in the program something like this is called:
table[bucket].push_back(1);
My question is, how come when declaring as *table I can use the bracket operator [] but if I declare it without the * then I can no longer use the bracket operator?
ex:
std::list<int> *table;
table[bucket].... OKAY
std::list<int> table;
table[bucket]... NOT OKAY
So when * is used, it's like there is a list at each bucket. so table[1] is a list, table[2] is another list. How are they achieving this by using *?
I've noticed I can do this with other types as well
ex:
int *test;
test[index]... OKAY
int test;
test[index]... NOT OKAY
this obviously has something to do with the pointer declaration but after countless reading and looking around, I can't seem to understand this. My thinking is that "std::list *table" creates a pointer to a list. But that doesn't clear anything up about how I am now able to use [].
Any clarification is greatly appreciated.