简体   繁体   English

Boost 1.59 编译错误

[英]Boost 1.59 compile error

After updating my files to boost_1.59.0 i get an ambyguous error.将我的文件更新到boost_1.59.0我收到一个不明确的错误。 I can't understand what's wrong because in boost 1.43 all work's fine.我不明白出了什么问题,因为在 boost 1.43 中一切正常。

This is my boost declaration and my function.这是我的 boost 声明和我的功能。

    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) );
    }

I also tried with auto in c++11我也尝试过在 c++11 中使用auto

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

Here is my error log gcc49 http://pastebin.com/p1KLqs9H I can't write here the error is too big.这是我的错误日志 gcc49 http://pastebin.com/p1KLqs9H我不能在这里写错误太大了。

I'am stucked on this error for 4 days.我被这个错误困住了 4 天。 :( :(

Here is vid.h这是 vid.h

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;
};

By looking at the error, it looks like you have to define a hash function for the type VID to be able to use it as a key in a map.通过查看错误,您似乎必须为类型VID定义一个哈希函数才能将其用作映射中的键。

Standard hash functions are already defined in the STL for basic types, but you have to define for yourself a specific one for your domain types. STL 中已经为基本类型定义了标准哈希函数,但您必须为自己的域类型定义一个特定的哈希函数。

Usually, it's enough to do something like this:通常,做这样的事情就足够了:

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
        }
    };
}

The difficulties are usually in understanding how to create the hash.困难通常在于理解如何创建哈希。 In my experience, for user defined classes, I've ever used the standard specialization with some data members, the most significant ones.根据我的经验,对于用户定义的类,我曾经对一些数据成员(最重要的数据成员)使用标准特化。

In your case, as an example, you could cast the DWORD s to a couple of unsigned int s and use them to get the hash by using std::hash<unsigned int> (I'm assuming that that's the DWORD from the Windows API, that is a 32 bit unsigned integer as far as I remember).在您的情况下,例如,您可以将DWORD s 转换为几个unsigned int s 并使用它们通过使用std::hash<unsigned int>来获取散列(我假设那是 Windows 中的DWORD API,据我所知,这是一个 32 位无符号整数)。

As already said in the comments, see here for further details.正如评论中已经说过的,请参阅此处了解更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM