Download

Multiple arguments in a constructor - a topic more than likely answered to death!

Hey all,

I know this has been answered to death in a lot of different contexts but I wasn’t sure how this applied to my case so I might as well ask it anyway!

The book I’m running through now is walking me through creating a CombatAction which is inheriting from a class called ICombatAction.
Inside the ICombactAction.h, it’s just declaring two virtual functions to be overriden, BeginExecuteAction(which takes an argument of a custom Character class) and Execute Action(which takes in an argument of DeltaSeconds).

So creating the TestCombatAction.h, it describes to declare



public:
TestCombatAction(UGameCharacter* target);


and in the cpp. file to type the constructor as



TestCombatAction::TestCombatAction(UGameCharacter* target)
{
  this->target = target;
}


However, I thought this was weird as I’ve been using constructors up to this point as



(const FObjectInitializer& ObjectInitializer)
      : Super(ObjectInitializer)


And sure enough this flipped out


TestCombatAction.cpp(7) : error C2084: function 'TestCombatAction::TestCombatAction(UGameCharacter *)' already has a body

The use of the TestCombatAction is to be used as an action which takes in a target and would be using UFUNCTIONs inside the header to expose to the UI Widget Blueprint as well as describing me to use it in classes as



this->action = new TestCombatAction(target);


So I’m looking for a way now to pass multiple arguments into the constructor.