C++ 使用同一类的std::无序指针集初始化
我试图创建一个类,该类包含指向同一类的C++ 使用同一类的std::无序指针集初始化,c++,class,c++11,hashset,stdset,C++,Class,C++11,Hashset,Stdset,我试图创建一个类,该类包含指向同一类的std::unordered_set,但在声明该类之前找不到准备哈希函数的方法 struct hash { inline std::size_t operator()(Vertex const * & other); }; struct Vertex { // ... double x, y, z; std::unordered_set<Vertex *, hash> touching; }; inlin
std::unordered_set
,但在声明该类之前找不到准备哈希函数的方法
struct hash
{
inline std::size_t operator()(Vertex const * & other);
};
struct Vertex
{
// ...
double x, y, z;
std::unordered_set<Vertex *, hash> touching;
};
inline std::size_t hash::operator()(Vertex * const & other) const
{
return ((hash<double>()(other->x))>>1)^
((hash<double>()(other->y)) )^
((hash<double>()(other->z))<<1);
}
struct散列
{
内联std::size_t运算符()(顶点常量*&其他);
};
结构顶点
{
// ...
双x,y,z;
std::无序设置触摸;
};
内联std::size\u t hash::operator()(顶点*常量和其他)常量
{
返回((hash()(其他->x))>>1)^
((散列()(其他->y)))^
((hash()(other->z))我假设您指的是,在hash::operator()
中,如果是,请指定完整的范围和包含。然后所有这些都需要顶点
类的前向声明,然后
#包括
#include//std::hash
struct Vertex;//向前声明“Vertex”
结构散列
{
std::size_t操作符()(顶点*其他)常量;
};
结构顶点
{
双x,y,z;
std::无序设置触摸;
};
std::size\u t hash::operator()(顶点*其他)常量
{
返回((std::hash()(其他->x))>>1)^
((std::hash()(其他->y)))^
((std::hash()(其他->z))
#include <unordered_set>
#include <functional> // std::hash
struct Vertex; // forward declare the `Vertex`
struct hash
{
std::size_t operator()(Vertex* other) const;
};
struct Vertex
{
double x, y, z;
std::unordered_set<Vertex*, ::hash> touching;
};
std::size_t hash::operator()(Vertex* other) const
{
return ((std::hash<double>()(other->x)) >> 1) ^
((std::hash<double>()(other->y))) ^
((std::hash<double>()(other->z)) << 1);
}