c++ 类继承

#include 

using namespace std;
int blood=10000;
class hero
{
protected:
    string name;
    int hp;
    int attack;
public:
    hero():name("ds"),hp(500),attack(50){}
    hero(string name,int hp,int attack):name(name),hp(hp),attack(attack){}
    virtual void Atk()
    {
        blood-=0;
    }
};
class P:public hero
{
    int ap_atk=50;
public:
    P():hero(){}
    P(string name,int hp,int attack):hero(name,hp,attack){}
    void Atk()
    {
        blood-=(attack+ap_atk);
    }
};
class D:public hero
{
    int ad_atk=100;
public:
    D():hero(){}
    D(string name,int hp,int attack):hero(name,hp,attack){}
    void Atk()
    {
        blood-=(attack+ad_atk);
    }
};
int main()
{
    D a;
    P b("hs",550,50);
    while (1)
    {
        a.Atk();
        cout<<"A被打了剩余blood="<

有道云笔记

你可能感兴趣的:(c++)