我需要为我的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