I'm making a thingy and today I got the C2864 Error. I am new to C so I'm actually kind of lost.
#ifndef MONSTER_ZOMBIE_H
#define MONSTER_ZOMBIE_H
// class definition
class CZombie : public CBaseMonster {
public:
virtual void Spawn(void);
virtual void Precache(void);
virtual void HandleAnimEvent(MonsterEvent_t *pEvent);
virtual void PainSound(void);
virtual void DeathSound(void);
virtual void AlertSound(void);
virtual void IdleSound(void);
virtual void AttackSound(void);
virtual void TraceAttack(entvars_t *pevAttacker, float flDamage, Vector vecDir, TraceResult *ptr, int bitsDamageType);
virtual bool CheckRangeAttack1(float flDot, float flDist) { return false; }
virtual bool CheckRangeAttack2(float flDot, float flDist) { return false; }
virtual int TakeDamage(entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType);
virtual int IgnoreConditions(void);
virtual int Classify(void);
virtual int Save(CSave &save);
virtual int Restore(CRestore &restore);
static TYPEDESCRIPTION m_SaveData[];
static const char *pAttackSounds[];
static const char *pIdleSounds[];
static const char *pAlertSounds[];
static const char *pPainSounds[];
static const char *pDeathSounds[];
static const char *pAttackHitSounds[];
static const char *pAttackMissSounds[];
protected:
BOOL m_flDebug = false;
float m_flBulletDR = 0.0;
float m_flNextFlinch;
float m_flHitgroupHead;
float m_flHitgroupChest;
float m_flHitgroupStomach;
float m_flHitgroupArm;
float m_flHitgroupLeg;
float m_flDmgOneSlash;
float m_flDmgBothSlash;
};
#endif // MONSTER_ZOMBIE_H
Visual Studio says that It's BOOL m_flDebug = false; and float m_flBulletDR = 0.0; are the cause of the error, but I just don't really know how to fix this. All I tried was to move these two lines out of "protected:" and the code actually compiles after that, but said zombie just becomes invulnerable! I looked at the similar questions here but didn't really learn anything from explanations there
CodePudding user response:
The code you are trying only becomes legal with C 11. So change your compiler options to be at least C 11 (not sure if this is possible with Visual Studio 2010, you really should upgrade your compiler as well).
Or do things the old fashioned way with a constructor.
class CZombie : public CBaseMonster {
public:
CZombie() : m_flDebug(false), m_flBulletDR(0.0) {}
...
};
If you really don't know about constructors then there are some serious gaps in your C knowledge.