假设我用我自己的类作为键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