我正在设置哈希表,并且我已经计算了密钥,并且想要确定数组中的那个点是否已经包含了某些内容。我想我应该检查它是否为空,以查看空间是否为空或是否已被删除。 del.compare
用于检查第一个名称字符串是否已被"DEL"
替换,这就是我如何标记已删除并准备重写的元素。
我收到错误:
error: no match for ‘operator!=’ in ‘(((Student*)this)->Student::studentList + ((unsigned int)(((unsigned int)((Student*)this)->Student::key) * 20u)))->Student::studentEntry::FIRST != 0’
对于这一行:
if(studentList[key].FIRST != NULL || del.compare(studentList[key].FIRST) != 0)
在此实例中使用!=
有什么问题?
编辑del.compare
:
我只是使用字符串库比较,在这种情况下del
在函数中初始化:
string del("DEL");
和studentList[key].FIRST
对应于指向字符串结构的指针,初始化为10
。 studentList[0].FIRST
应该是10
数组中第一个条目的第一个名称,它应该为空。
这是我在构造函数中声明它的方式:
studentList = new studentEntry[10];
编辑FIRST
:
FIRST
在Students
结构内的studentEntry
类中声明。那部分看起来像:
class Student
{
private:
struct studentEntry
{
string FIRST;
};
studentEntry *studentList;
int key;
int index;
public:
void add(string &firstname);
Student();
};
这是Student
类的构造函数,它也可能是相关的:
Student::Student()
{
studentList = new studentEntry[10];
key = 0;
index = 0;
}
编辑add
:
以下是add
函数,其中进行比较导致错误:
void Student::add(string &firstname)
{
string del("DEL");
//find key to know which bucket to use
key = index % 10;
//check if spot in studentList is empty or has been removed
if(studentList[key].FIRST != NULL || del.compare(studentList[key].FIRST) != 0)
{
//do stuff
}
}
答案 0 :(得分:1)
编译器说 del.compare
的结果不能与0
你没有展示 del.compare
的任何内容,所以不能说更多
目前缺少FIRST
...
以后某个时间 - FIRST
现在显示为string
,大概是std::string
。
您无法将std::string
与0或nullptr
进行比较。
但您可以将其length()
与0比较,例如。