1. 程式人生 > >通過起別名實現一類函數指針效果

通過起別名實現一類函數指針效果

ret return smo 通過 方式 cast span asa 類函數

bool IsNpc(APawn* pPawn) const {return (NULL != Cast<ASA2NpcPawn>(pPawn));}
bool IsMonster(APawn* pPawn) const ...
bool IsPet...

typedef bool (*CheckPawnType)(APawn* pPawn) const;
void MaskPawn(ASA2Pawn* aPawn, CheckPawnType CheckCall)
{
      if(aPawn && (*CheckCall)(aPawn))
      {
           aPawn
->bMask = true; } }

調用方式:

MaskPawn(aPawn, &IsNpc);

MaskPawn(aPawn, &IsPet);

通過起別名實現一類函數指針效果