我搜索了很多页面,我认为我已经知道如何编写std :: hash。但我不知道该把它放在哪里。
这里提供了一个示例 http://en.cppreference.com/w/cpp/utility/hash。
然而,在文件instance_management.h
的命名空间ca
中定义了我的类型Instance
。我想在同一文件中的另一个类InstanceManager
中使用unordered_set<Instance>
。所以我写了以下代码:
namespace std
{
template <> struct hash<ca::Instance>
{
size_t operator()(const ca::Instance & instance) const
{
std::size_t seed = 0;
// Some hash value calculation here.
return seed;
}
};
} // namespace std
但是我应该把它放在哪里呢?我尝试了很多地方,但都失败了。
我正在使用Visual Studio 2013。我尝试将先前的代码放在一些位置,但都无法编译它。
// location 1
namespace ca
{
class Instance {...}
class InstanceManager
{
// ... some other things.
private unordered_set<Instance>;
}
}
// location 2
instance_management.h
有什么问题吗? - vsoftco