在我提出这个问题之前,我可能应该做更多的研究,但是我对在线搜索感到非常沮丧。
我正在做一个学校作业,它涉及实现一个哈希表,所以我尝试用这样的链接来初始化桶
在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];
}
我现在正在使用代码块,我得到的错误是插入行
错误:在此范围|
中未声明'buckets'
我不知道为什么不是,有人可以帮助我,谢谢!
答案 0 :(得分:2)
你忘记了Hashtable::
。它应该是:
void Hashtable::insert(char * value,int r, string previous)
{
int find=hashfcn(value);
Node *x =buckets[find];
}
我相信你已经知道了这一点,但就像现在一样,你只是定义一个自由函数,它不知道buckets
是什么。您需要指定在函数名称之前使用Hashtable
定义Hashtable::
的成员函数,然后可以看到buckets
表示调用Hashtable
的成员变量1}}名为buckets
。