_handlers[ItemSpecialAttrId::AddGold] = boost::bind(&ItemManager::UseAddGold, this, _1, _2);
_handlers[ItemSpecialAttrId::AddGoldNote] = boost::bind(&ItemManager::UseAddGoldNote, this, _1, _2);
_handlers[ItemSpecialAttrId::SynthMaterial] = boost::bind(&ItemManager::UseSynthMaterial, this, _1, _2);
_handlers[ItemSpecialAttrId::EnhanceNpcExp] = boost::bind(&ItemManager::UseEnhanceNpcExp, this, _1, _2);
_handlers[ItemSpecialAttrId::GetAttribute] = boost::bind(&ItemManager::UseGetAttribute, this, _1, _2);
_handlers[ItemSpecialAttrId::GainReinforceProp] = boost::bind(&ItemManager::UseGainReinforceProp, this, _1, _2);
[cpp]
//specialAttrId 是外部传递过来的参数 对应map中的key
map
if (itFind == _handlers.end())
return;
if (itFind->second)
itFind->second(roleId, specialAttrValue);
//specialAttrId 是外部传递过来的参数 对应map中的key
map
if (itFind == _handlers.end())
return;
if (itFind->second)
itFind->second(roleId, specialAttrValue);
这样写 通过注册的方式来调用不同的函数接口,看着舒服多了,也灵活多了, 到有新增的case情况 直接填写一个:
[cpp]
_handlers[ItemSpecialAttrId::GainReinforceProp] = boost::bind(&ItemManager::UseGainReinforceProp, this, _1, _2);