共享PTR的无序图中断C++;程序 我在当前的C++项目中使用了无序的映射> /COD>,并存在以下问题:

共享PTR的无序图中断C++;程序 我在当前的C++项目中使用了无序的映射> /COD>,并存在以下问题:,c++,debugging,boost,c++11,C++,Debugging,Boost,C++11,当我将一对对象插入到无序_映射中时,程序中断,窗口显示它“[…].exe已停止工作”,而没有在控制台(cmd)上提供任何信息。一些示例代码: #包括 #包括 #包括 int main(int argc,字符**argv){ 网络游戏; boost::asio::io_服务io_服务; NetPlayerPtr网络(新的NetPlayer(io_服务,游戏)); PlayerPtr玩家(新玩家); std::无序地图播放器地图; //在这里,它打破了: 玩家地图[玩家]=网络; 返回0; } 我

当我将一对对象插入到
无序_映射
中时,程序中断,窗口显示它“[…].exe已停止工作”,而没有在控制台(cmd)上提供任何信息。一些示例代码:

#包括
#包括
#包括
int main(int argc,字符**argv){
网络游戏;
boost::asio::io_服务io_服务;
NetPlayerPtr网络(新的NetPlayer(io_服务,游戏));
PlayerPtr玩家(新玩家);
std::无序地图播放器地图;
//在这里,它打破了:
玩家地图[玩家]=网络;
返回0;
}
我已经尝试过的: 我试着用一个试扣把钓索包起来,但没有成功

有关守则的详情: NetPlayerPtr和PlayerPtr是
boost::shared_ptr
对象,前者包含一些
boost::asio
对象,如
io_service
socket
,后者包含多个自定义对象

我使用MinGW gcc进行编译,在64位Windows上启用了C++11


如果需要更多详细信息,请询问。

好的,让我们看看您链接到的代码:

namespace std
{
    template<>
    class hash<Player>
    {
    public:
        size_t operator()(const Player &p) const
        {
            // Hash using boost::uuids::uuid of Player
            boost::hash<boost::uuids::uuid> hasher;
            return hasher(p.id);
        }
    };

    template<>
    class hash<PlayerPtr>
    {
    public:
        size_t operator()(const PlayerPtr &p) const
        {
            return hash<PlayerPtr>()(p);   // infinite recursion
        }
    };
}
名称空间std
{
模板
类散列
{
公众:
大小\u t运算符()(常数播放器和p)常数
{
//使用播放器的boost::uuids::uuid进行哈希
boost::散列哈希器;
返回哈希器(p.id);
}
};
模板
类散列
{
公众:
大小运算符()(常量PlayerPtr&p)常量
{
return hash()(p);//无限递归
}
};
}
hash::operator()中有一个有限递归。您可能想要的是:

return hash<Player>()(*p);
返回hash()(*p);
或:

returnhash()(p->get());

取决于您是想通过其内部id还是地址来识别播放机。

好的,让我们看看您链接到的代码:

namespace std
{
    template<>
    class hash<Player>
    {
    public:
        size_t operator()(const Player &p) const
        {
            // Hash using boost::uuids::uuid of Player
            boost::hash<boost::uuids::uuid> hasher;
            return hasher(p.id);
        }
    };

    template<>
    class hash<PlayerPtr>
    {
    public:
        size_t operator()(const PlayerPtr &p) const
        {
            return hash<PlayerPtr>()(p);   // infinite recursion
        }
    };
}
名称空间std
{
模板
类散列
{
公众:
大小\u t运算符()(常数播放器和p)常数
{
//使用播放器的boost::uuids::uuid进行哈希
boost::散列哈希器;
返回哈希器(p.id);
}
};
模板
类散列
{
公众:
大小运算符()(常量PlayerPtr&p)常量
{
return hash()(p);//无限递归
}
};
}
hash::operator()中有一个有限递归。您可能想要的是:

return hash<Player>()(*p);
返回hash()(*p);
或:

returnhash()(p->get());

这取决于你是想通过玩家的内部id还是地址来识别玩家。

不,我对GDB之类的调试器(如果你这么说的话)没有过期权限。@m--s现在是你的机会了!似乎是真的。这方面有什么好的资源吗D(开玩笑,我自己去谷歌一下)我们能看到
std::hash
对于
PlayerPtr
的专门化吗?另外,为什么要使用
boost::shared_ptr
而不是
std::shared_ptr
?Erm。。。你的
散列中有一个无限递归:)不,我对GDB这样的调试器没有过期性(如果你说的是这个)。@m--s现在是你的机会了!似乎是真的。这方面有什么好的资源吗D(开玩笑,我自己去谷歌一下)我们能看到
std::hash
对于
PlayerPtr
的专门化吗?另外,为什么要使用
boost::shared_ptr
而不是
std::shared_ptr
?Erm。。。在你的
散列中有一个无限递归
:)嗯。。。我需要为变量提供
hash
。哦,好吧,让我们只
std::hash
it!天才!:)隐马尔可夫模型。。。我需要为变量提供
hash
。哦,好吧,让我们只
std::hash
it!天才!:)