0

I asked a similar question here C++ delegate creation but I need to do this with a new restriction. I'll quickly restate the question

I was wondering if theres a way to mimic this delegate behaviour (from C#) in 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;
                })

I need to be able to do this without using C++0x as I'm stuck on a version of gcc the doesnt support C++0x lambdas. I have the boost library available but I'm jut getting into it so I can't figure out how to do this specifically.

Thanks in advance for the help

Community
  • 1
  • 1
Megatron
  • 2,871
  • 4
  • 40
  • 58

2 Answers2

0

Either library should work for creating unnamed functions.

See this question too, note that the two libraries will be merged some day.

Community
  • 1
  • 1
Sam Miller
  • 23,808
  • 4
  • 67
  • 87
0

boost::bind is the usual solution to this problem. Refer to their documentation for details.

Puppy
  • 144,682
  • 38
  • 256
  • 465