我想知道是否有办法在 C++ 中模仿这种委托行为(来自 C#)
new ModifyTargetingStatus("Reversal", "Reverses physical attacks back at the user", -1, new List<CALL_CONDITION>(){CALL_CONDITION.Targetted}, attemptChange: delegate(CharacterMove move, BattleCharacter[] users, ref BattleCharacter[] targets, BattleCharacter holder, BattleField field)
{
if (targets != null && targets.Length == 1 && targets[0] == holder &&
(move.MoveClass == MOVE_CLASS.MC_BASIC_ATTACK ||
move.MoveClass == MOVE_CLASS.MC_STACKED_ATTACK) &&
!move.MoveFlags.Contains(MOVE_FLAG.MF_UNREFLECTABLE))
{
targets = users;
move.Reflected = true;
return true;
}
return false;
})
我看过 boost::function 和 boost::bind 以及一篇关于代码项目上的 FastDelegates 的文章,但它们似乎都要求您在其他地方定义函数然后绑定到它。如果可能的话,我希望能够在对象创建时提供该功能
提前致谢
这些称为匿名函数 (lambda),在 C++ 中不受支持。来自维基百科文章 http://en.wikipedia.org/wiki/Anonymous_function: “匿名函数已添加到 C++ 语言中C++0x http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions."
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)