C++静态成员变量的初始化

C++类内不能初始化某些静态成员变量,必须在.cpp里面进行初始化。

这是.cpp文件

1 bool MyWarrior::_isInit = false;
2 const char MyWarrior::WARRIOR_NAME[WARRIOR_COUNT][30]={"orcwarrior","skeletonwarrior","swampmonster","whitebear"};
3 const int MyWarrior::WARRIOR_ATTACK_FRAMES_COUNT[WARRIOR_COUNT]={10,9,12,13};
4 const int MyWarrior::WARRIOR_WALK_FRAMES_COUNT[WARRIOR_COUNT]={8,8,16,8};
5 const int MyWarrior::WARRIOR_DIE_FRAMES_COUNT[WARRIOR_COUNT]={12,9,13,9};
6 const int MyWarrior::WARRIOR_BIRTH_KFRAMES_COUNT[WARRIOR_COUNT]={0,14,0,0};

 

这是.h文件

 

 

 1 class MyWarrior: public Warrior{
 2 public :
 3     const static int WARRIOR_COUNT = 4;
 4     //兽人 骷髅兵 沼泽怪 白熊
 5     const static char WARRIOR_NAME[WARRIOR_COUNT][30];
 6     const static int WARRIOR_ATTACK_FRAMES_COUNT[WARRIOR_COUNT];
 7     const static int WARRIOR_WALK_FRAMES_COUNT[WARRIOR_COUNT];
 8     const static int WARRIOR_DIE_FRAMES_COUNT[WARRIOR_COUNT];
 9     const static int WARRIOR_BIRTH_KFRAMES_COUNT[WARRIOR_COUNT];
10 } 
posted @ 2014-01-06 21:33  phk52  阅读(351)  评论(0)    收藏  举报