我已经有3-4个unordered_maps with boost,并且一切正常。 现在我想做另一个,但我从地图上得到了错误的输出。
STRUCT:
struct sQUICK_SLOT_PROFILE
{
TBLIDX tblidx;
BYTE bySlot;
BYTE byType;
HOBJECT hItem;
};
功能:
sQUICK_SLOT_PROFILE* GetQuickSlotSkillDataFromList(BYTE SlotIndex);
void AddQuickSlotSkillDataToMyList(BYTE SlotIndex, sQUICK_SLOT_PROFILE* skilldata);
boost::unordered_map<BYTE, sQUICK_SLOT_PROFILE*> p_QuickSlotSkillData;
asQuickSlotData
BEGIN_PROTOCOL(GU_QUICK_SLOT_INFO)
BYTE byQuickSlotCount;
sQUICK_SLOT_PROFILE asQuickSlotData[10];
END_PROTOCOL()
添加到地图:
res->asQuickSlotData[slotID].tblidx = pSkillData->tblidx;
res->asQuickSlotData[slotID].bySlot = i;
res->asQuickSlotData[slotID].byType = (pSkillData->bySkill_Class==NTL_SKILL_CLASS_HTB?QUICK_SLOT_TYPE_HTB_SKILL:QUICK_SLOT_TYPE_SKILL);
res->asQuickSlotData[slotID].hItem = 0;
pPlayer->AddQuickSlotSkillDataToMyList(slotID, res->asQuickSlotData);
AddQuickSlotSkillDataToMyList函数:
void PlayerInfos::AddQuickSlotSkillDataToMyList(BYTE SlotIndex, sQUICK_SLOT_PROFILE* skilldata)
{
printf("ADD DATA %d %d %d %d %d \n", SlotIndex, skilldata->bySlot, skilldata->byType, skilldata->hItem, skilldata->tblidx);
p_QuickSlotSkillData.insert(make_pair(SlotIndex, skilldata));
}
现在获取数据函数:
sQUICK_SLOT_PROFILE* PlayerInfos::GetQuickSlotSkillDataFromList(BYTE SlotIndex)
{
itertype(p_QuickSlotSkillData) it = p_QuickSlotSkillData.find(SlotIndex);
if (p_QuickSlotSkillData.end() == it){
printf("error \n");
return 0;
}
sQUICK_SLOT_PROFILE* quickslot = it->second;
if (quickslot == NULL) {
printf(error 2 \n");
return 0;
}
printf("FOUND DATA %d %d %d %d %d \n", SlotIndex, quickslot->bySlot, quickslot->byType, quickslot->hItem, quickslot->tblidx);
return quickslot;
}
图片查看printf: http://s7.directupload.net/images/140924/we78r9kq.jpg
现在,您看到它将正确的数据添加到地图中,但输出是垃圾。
什么错了?我不明白我已经坐了3个小时..
有一个解决方案:
void PlayerInfos::AddQuickSlotSkillDataToMyList(BYTE SlotIndex, sQUICK_SLOT_PROFILE* skilldata)
{
printf("ADD DATA %d %d %d %d %d \n", SlotIndex, skilldata->bySlot, skilldata->byType, skilldata->hItem, skilldata->tblidx);
sQUICK_SLOT_PROFILE* rofl = new sQUICK_SLOT_PROFILE;
rofl->bySlot = skilldata->bySlot;
rofl->byType = skilldata->byType;
rofl->hItem = skilldata->hItem;
rofl->tblidx = skilldata->tblidx;
p_QuickSlotSkillData.insert(make_pair(SlotIndex, rofl));
// delete rofl;
}