假設我用我自己的類作爲鍵std::unordered_map
例如需要的std :: unordered_map構造
class MyClass {
public:
int a, b;
}
www.cplusplus.com列出了下面的構造函數可用於:
explicit unordered_map (size_type n,
const hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& alloc = allocator_type());
你能不能給一個例子,我可以如何使用上述構造函數的所有參數填充構造我的std::unordered_map<MyClass, std::string>
?
【這裏這個例子(http://en.cppreference.com/w/cpp/container/unordered_map/unordered_map)應該給你一個好主意什麼是必須的。 – juanchopanza 2013-03-24 17:23:13
@juanchopanza我明白哈希和key_equal函數可以被指定爲模板的一部分。但是,他們可以直接傳遞給構造函數,而無需在模板中指定它們?如果是這樣,怎麼樣? – 2013-03-24 17:34:44
您只需將函數的實例傳遞給構造函數。特定的位置取決於你所調用的構造函數。 – juanchopanza 2013-03-24 17:36:47