我設置了一個哈希表,並且計算了該鍵,並且想要確定該數組中的該點是否已經有內容。我想我應該檢查它是否爲null,以查看該空間是否爲空或者是否已被刪除。 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
相當於一個指向一個struct字符串,初始化爲10
。 studentList[0].FIRST
應該是10
數組中第一個條目的名字,它應該是空的。
以下是我宣稱它在構造函數中:
studentList = new studentEntry[10];
編輯約FIRST
:
FIRST
在studentEntry
結構內部的Students
類被聲明。這部分看起來像:
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
}
}
我更新了這個問題,對不起,我以爲問題出現在'||' – manalishi 2013-02-24 01:26:45
@manalishi的前半部分:顯然我的回答是錯誤的。請顯示一個完整的小例子程序。 – 2013-02-24 01:36:24
好的,我添加了更多關於'FIRST'的信息以及我使用 – manalishi 2013-02-24 01:51:49