문제

hi i am tryng to implement a trait class of std::hash struct but i cannot progress from here:

#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;
    }
도움이 되었습니까?

해결책

Looks more like you are coding a specialisation of std::hash. For that, you probably need to define the class before you do the specialisation...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top