1234567891011121314151617181920212223242526272829303132333435363738394041
#include <iostream> #include <vector> using namespace std; class NPC { protected: int hp, mana, level, damage; public: void DealDamage(NPC, int); void SetLevel(int); NPC(); }; NPC::NPC() { level = 1; hp = level*10; mana = level*5; damage = level*2; } void NPC::DealDamage(NPC npc, int dmg) { } void NPC::SetLevel(int i) { level = i; hp = level*10; mana = level*5; damage = level*2; } int main() { vector<NPC> npc(2); // DealDamage() with npc[0] to npc[1] system("pause"); return 0; }
1234567891011
void NPC::DealDamage(NPC& npc, int dmg) { npc.hp -= dmg; } int main() { vector<NPC> npc(2); // DealDamage() with npc[0] to npc[1] npc[0].DealDamage(npc[1], 10); }
but hp is protected, not public :X