我需要爲我的Note對象使用unordered_multimap
,而這些鍵將是我的對象的measureNumber
成員。我試圖執行它as shown here但我卡住了。unordered_multimap用法和操作符覆蓋
首先,我不明白爲什麼我必須覆蓋operator==
才能使用它。我也很困惑,爲什麼我需要一個哈希以及如何實現它。 In this example here,這兩件事都沒有完成。
因此,基於第一個例子,這是我有:
class Note {
private:
int measureNumber;
public:
inline bool operator== (const Note ¬eOne, const Note ¬eTwo);
}
inline bool Note::operator ==(const Note& noteOne, const Note& noteTwo){
return noteOne.measureNumber == noteTwo.measureNumber;
}
我不知道如何實現,雖然散列部。有任何想法嗎?
我將如何構建多圖,像這樣? 'multimap noteMap;'運算符<'函數的定義是在頭文件還是在實現文件中? –
networkprofile
2012-04-12 01:29:04
@Sled好的,我希望這是你要找的。現在需要走了,祝你好運! – Potatoswatter 2012-04-12 01:41:02
我有getter和setter爲measureNumber,所以這不是一個真正的問題。我現在認識到,除了特定的筆記之外很難刪除,因爲它們是通過measureNumber進行映射的,但我需要這種模型進行實時合成,因爲我需要儘快地通過度量來找到筆記,這看起來像是一個迄今爲止的好方法。 (我不得不多次改變事情)非常感謝您的幫助! – networkprofile 2012-04-12 01:56:09