2011-11-26 63 views
0

在我问这个问题之前,我应该做更多的研究,但是我对在线搜索感到沮丧。实现散列表,插入导致“范围”错误的函数

Im做学校里的功课,它包括实现一个哈希表,所以我尝试用链接这样

内Hashtable.h

private: 

Node **buckets; //trying to create an array of pointers 

内Hashtable.cpp

初始化桶
Hashtable::Hashtable() 
{ 
buckets=new Node*[1000]; 
} 

void insert(char * value,int r, string previous) 
{ 
int find=hashfcn(value); 
Node *x =buckets[find]; 
} 

即时使用代码块,我得到的错误是插入行

error: 'buckets' was not declared in this scope|

我不知道为什么它不是,有人可以帮助我,谢谢!

回答

2

您忘记了Hashtable::。它应该是:

void Hashtable::insert(char * value,int r, string previous) 
{ 
int find=hashfcn(value); 
Node *x =buckets[find]; 
} 

我相信你已经知道这一点,但因为它是现在,你只是定义一个免费的功能,它具有不知道什么buckets是。您需要指定您在函数名称前面定义了HashtableHashtable::的成员函数,然后您可以看到buckets指的是调用Hashtable的成员变量buckets