我在想,如果那裏有一個方法來模仿(從C#)在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 ::功能和boost ::綁定和有關FastDelegates的文章在代碼項目上,但他們似乎都要求你在其他地方定義函數然後綁定到它。我希望能夠提供在創建對象如果可能的話
由於功能提前
您使用的是C++ 0x嗎? – 2011-03-08 19:58:09
Im使用MSVC 2010/boost – Megatron 2011-03-08 20:00:24
2010支持足夠的C++ 0x來執行lambdas。有關詳細信息,請參閱以下內容:http://en.wikipedia.org/wiki/C%2B%2B0x#Lambda_functions_and_expressions – luke 2011-03-08 20:02:49