I have a HashTable< Customer > as a member in another class.
The constructor for HashTable< T > takes an int value in order to determine the size of the HashTable's array.
HashTable(int numItems) { ... } //constructor
The following declaration
HashTable<Customer> customers(10000); //doesn't call constructor???
receives the error "expected a type specifier" underneath the 10000. When I remove the 10000, I receive the error "Function definition for customers not found." This leads me to believe that the compiler is treating my object declaration as a function declaration.
When I declare my HashTable using dynamic allocation,
HashTable<Customer> * customers = new HashTable<Customer>(10000); //works
there is no confusion with the compiler.
Why does the dynamic allocation work, but not the other?
Edit: Here is a minimal code that has the same issue stated above.
#ifndef _BUSINESS_LOGIC
#define _BUSINESS_LOGIC
#include "HashTable.h"
class BusinessLogic
{
public:
BusinessLogic();
~BusinessLogic();
void start();
private:
HashTable<int> * custom = new HashTable<int>(10000); //works
HashTable<int> customers(10000); //error
};
#endif
#ifndef _HASH_TABLE
#define _HASH_TABLE
template<class T>
class HashTable
{
public:
HashTable(int numItems) {
if (numItems <= 0) {
throw std::invalid_argument("Invalid HashTable size");
}
currItems = 0;
//B must be the next prime after 2 * numItems
B = numItems;
}
~HashTable() {
}
private:
int B; //size of itemArray
};
#endif