gpt4 book ai didi

C++ std::hash specilization trait 编译错误

转载 作者:行者123 更新时间:2023-11-28 02:51:55 24 4
gpt4 key购买 nike

嗨,我正在尝试实现 std::hash 结构的特征类,但我无法从这里取得进展:

#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 的特化代码。为此,您可能需要在进行特化之前定义类...

关于C++ std::hash specilization trait 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22846308/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com