c++ std::hash specilization trait compile error
c++ std::hash specilization trait compile error
嗨,我正在尝试实现 std::hash 结构的 trait 类,但我无法从这里取得进展:
#include <iostream>
#include <functional>
namespace std {
template<>
struct hash< Test::AckMsgType<Test::EACKMSGTYPE::ACKMSG_POST> >
{
typedef std::size_t value_type;
typedef Test::AckMsgType<Test::EACKMSGTYPE::ACKMSG_POST> AckMsg;
value_type operator()(const AckMsg & aAckMsg) const
{
value_type const h1 ( std::hash<int>()(aAckMsg.getProxyID()) );
value_type const h2 ( std::hash<int>()(aAckMsg.getCmdID()) );
value_type const h3 ( std::hash<int>()(aAckMsg.getHdrMsgId()) );
return (h1 ^ (h2 << 1)) ^ (h3 << 1) ;
}
};
}
namespace Test {
enum class EACKMSGTYPE
{
ACKMSG_POST,
ACKMSG_RELEASE
};
//definicion de los traits
template<EACKMSGTYPE>
class AckMsgType
{};
template<>
class AckMsgType<EACKMSGTYPE::ACKMSG_POST>
{
public:
explicit AckMsgType(const int & aID):ID(aID)
{
}
void setCmdId(const int & aCmdId)
{
CmdID =aCmdId;
}
void setMsgHeaderId(const int & aHeaderId)
{
HdrMsgId=aHeaderId;
}
void buildAckIdentifier()
{
}
int getProxyID()
{
return (ID);
}
int getCmdID() const
{
return CmdID;
}
int getHdrMsgId() const
{
return HdrMsgId;
}
private:
const int ID;
int CmdID;
int HdrMsgId;
int AckMsgId;
};
}
int main()
{
return 0;
}
看起来更像是你正在编写std::hash的专业化。为此,您可能需要在进行专业化之前定义类......
相关文章:
- "error: no matching function for call to"构造函数错误
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 使用 LuaBridge 将 LuaJIT 绑定到C++会导致"PANIC: unprotected error"
- OpenMP卸载说'fatal error: could not find accel/nvptx-none/mkoffload'
- C++错误:"error: int aaa::bbb is protected within this context"
- 尝试链接我的着色器时,我收到错误代码"error c5145 must write to gl_position"
- C++,在int数组中输入字符串或字符会输出0,而不是ascii或error
- 使用 cmake 的 LLVM 构建在 tsan_libdispatch_mac.cc 期间失败; "Error: conflicting types for ..."
- C++ "error: invalid use of void expression"
- struct.error:解压缩 C++ 结构时,解包需要 288 字节的缓冲区
- 如何修复"error: ‘_1’ was not declared in this scope"?
- 从不同目录执行时"symbol lookup error:",否则从构建目录执行时按预期工作
- Compile Error with Eluna - QueryResult.cpp
- Luarocks luasql-mysql compile error
- 构建 OpenCL 内核时"Compile Server Error."
- BeagleBoneBlack Cross Compile on Mac Error
- C++11 future::wait_for compile error
- c++ std::hash specilization trait compile error
- Boost asio TCP IP asio class compile error with Visual Studio.错误:C2228:'.close'左侧必须具有类/结构/联合
- Cocos2D-X compile Linux Error: Undefined Reference