目标:
1、封装UseAction(char* szpActionName)
2、避免头文件重复包含
3、#ifndef宏
BOOL TActionList::UseAction(char* szpActionName)
#include "StructGame.h"
TBACKPACK_LIST tBackPackList;//背包数组
TMonsterList tMosterList;//怪物数组
TActionList tActionlist;//动作数组
BOOL TActionList::UseAction(char* szpActionName)
{
GetData();//初始化动作数组
for (int i=0;i<12;i++)
{
if ((strcmp(tList[i].szpName,szpActionName)==0))
{
UseAction(i);
return TRUE;
}
}
return FALSE;
}
1、封装UseAction(char* szpActionName)
2、避免头文件重复包含
3、#ifndef宏
BOOL TActionList::UseAction(char* szpActionName)
#include "StructGame.h"
TBACKPACK_LIST tBackPackList;//背包数组
TMonsterList tMosterList;//怪物数组
TActionList tActionlist;//动作数组
BOOL TActionList::UseAction(char* szpActionName)
{
GetData();//初始化动作数组
for (int i=0;i<12;i++)
{
if ((strcmp(tList[i].szpName,szpActionName)==0))
{
UseAction(i);
return TRUE;
}
}
return FALSE;
}
本文详细介绍了如何在C++代码中优化动作列表使用函数,包括封装UseAction函数、避免头文件重复包含及使用#ifndef宏来防止预处理指令冲突。通过实例演示了动作列表类的实现,确保代码的高效性和可维护性。

被折叠的 条评论
为什么被折叠?



