I've just ran into a problem with this:
Code:
#include "stdafx.h"
using namespace std;
class HashTable
{
int data[100];
public:
HashTable();
~HashTable();
int operator[](char *rhs);
};
HashTable::HashTable()
{
for (int i = 0; i < 100; i++)
data[i] = 0;
}
HashTable::~HashTable()
{
}
// operator[]
int HashTable::operator[](char *rhs)
{
int hash = 0;
int i = 0;
// construct a hash from the string
for (; *(rhs + i) != 0; i++)
hash += static_cast<int>(*(rhs + i));
cout << "hash: " << hash << endl;
return 0;
}
int main(int argc, char* argv[])
{
HashTable *ht = new HashTable();
ht["lee"];
delete ht;
return 0;
}
Error:
Code:
c:\Documents and Settings\lee\Desktop\sandbox\sandbox.cpp(46) : error C2107: illegal index, indirection not allowed
Tis the first time I've had this error. I'm scared.
Oh I know the hash algorithm is corny and the data array seems a bit pointless, but I have plans, glorious glorious plans!.