Boost 1.59编译错误

Boost 1.59 compile error

本文关键字:错误 编译 Boost      更新时间:2023-10-16

将文件更新到boost_1.59.0后,我出现了一个动态错误。我不明白出了什么问题,因为在1.43增压中,所有工作都很好。

这是我的助推宣言和我的功能。

    boost::unordered_map<VID, size_t>::iterator iterTargetMap = rSkillUseInfo.TargetVIDMap.find(TargetVID);
if (rSkillUseInfo.TargetVIDMap.end() != iterTargetMap)
    {
        size_t MaxAttackCountPerTarget = 1;
        switch (SkillID)
            {
            case SKILL_SAMYEON:
            case SKILL_CHARYUN:
                MaxAttackCountPerTarget = 3;
                break;
            }
        if (iterTargetMap->second >= MaxAttackCountPerTarget)
            {
                sys_log(0, "SkillHack: Too Many Hit count from SkillID(%u) count(%u)", SkillID, iterTargetMap->second);
                return false;
            }
        iterTargetMap->second++;
    }
else
    {
        rSkillUseInfo.TargetVIDMap.insert( std::make_pair(TargetVID, 1) );
    }

我还在c++11 中试用了auto

auto iterator iterTargetMap = rSkillUseInfo.TargetVIDMap.find(TargetVID);

这是我的错误日志gcc49http://pastebin.com/p1KLqs9H我不能在这里写——错误太大了。

我被这个错误困扰了4天(

这是视频

class VID
{
public:
    VID() : m_id(0), m_crc(0)
    {
    }
    VID(DWORD id, DWORD crc)
    {
        m_id = id;
        m_crc = crc;
    }
    VID(const VID &rvid)
    {
        *this = rvid;
    }
    const VID & operator = (const VID & rhs)
    {
        m_id = rhs.m_id;
        m_crc = rhs.m_crc;
        return *this;
    }
    bool operator == (const VID & rhs) const
    {
        return (m_id == rhs.m_id) && (m_crc == rhs.m_crc);
    }
    bool operator != (const VID & rhs) const
    {
        return !(*this == rhs);
    }
    operator DWORD() const
    {
        return m_id;
    }
    void Reset()
    {
        m_id = 0, m_crc = 0;
    }
private:
    DWORD m_id;
    DWORD m_crc;
};

通过查看错误,您似乎必须为类型VID定义一个hash函数,才能将其用作映射中的键。

STL中已经为基本类型定义了标准散列函数,但您必须为自己的域类型定义一个特定的散列函数。

通常,做这样的事情就足够了:

namespace std {
    template<> struct hash<VID> {
        using argument_type = VID;
        using result_type = std::size_t;
        result_type operator()(argument_type const& vid) const {
            // what to put here depends on the type of VID
            // and how you want to create the hash
        }
    };
}

困难通常在于理解如何创建散列。根据我的经验,对于用户定义的类,我曾经对一些数据成员(最重要的数据成员)使用过标准专业化。

在您的情况下,例如,您可以将DWORD强制转换为几个unsigned int,并使用它们通过使用std::hash<unsigned int>来获取哈希(我假设这是来自Windows API的DWORD,据我记忆,这是一个32位无符号整数)。

如评论中所述,请参阅此处了解更多详细信息。