Reputation: 165
For my assignment I have to create a hash table and I've managed to write most of the hash table until I realized that I declared a static array in my header file. The hash table is suppose to implement a dynamically allocated array and I'm wondering where this array would get created? Would I put it in my header file or do I put it inside my constructor. If I create it in my constructor how will my other member functions access and modify the array since it's in the scope of my constructor. Thank you
Item* ptr = new Item[bucketcount];
Upvotes: 2
Views: 1719
Reputation: 427
I can't completely understand your question, but if your problem is a "scope" problem, you can solve it by declaring your array as a member of your HashTable class:
HashTable.cpp
class HashTable
{
private:
Item* items;
public:
HashTable()
{
items = new Item[size];
}
~HashTable()
{
delete[] items;
}
};
As a member it will be visible from every method of your HashTable class.
Upvotes: 2