类:继承-1

#include <iostream>
//类的三大特点:封装,继承,多态
class Player
{
public:
	int hp;
};
class Moster1
{
public:
	int id;
	int hp;
	int mp;
	int attack;
	void Attack(Player* player)
	{
		player->hp -= 10;
	}
};

class Moster2
{
public:
	int id;
	int hp;
	int mp;
	int attack;
	int skill;//比Moster1多的数据
	void Attack(Player* player)
	{
		player->hp -= 10;
	}
	void AttackSkill(Player* player)
	{
		player->hp -= 20;
	}
};


class Moster3
{
public:
	int id;
	int hp;
	int mp;
	int attack;
	int baoji;//暴击
	void Attack(Player* player)
	{
		player->hp -= 10;
	}
	void AttackBaoji(Player* player)
	{
		player->hp -= 100;
	}
};



void main()
{
	

	system("pause");

}

 

#include <iostream>
//类的三大特点:封装,继承,多态
class Player
{
public:
	int hp;
};

//基类:
class Moster1
{
public:
	int id;
	int hp;
	int mp;
	int attack;
	void Attack(Player* player)
	{
		player->hp -= 10;
	}
};
//Moster2公有继承自Moster1
//Moster1是Moster2的父类
//Moster2是Moster1的子类
class Moster2 : public Moster1
{
public:
	int skill;//比Moster1多的数据
	void AttackSkill(Player* player)
	{
		player->hp -= 20;
	}
};

//Moster3公有继承自Moster1
//Moster1是Moster3的父类
//Moster3是Moster1的子类
class Moster3 : public Moster1
{
public:
	int baoji;//暴击
	void AttackBaoji(Player* player)
	{
		player->hp -= 100;
	}
};

void main()
{
	
	std::cout<<sizeof(Moster1)<<std::endl;//16
	std::cout<<sizeof(Moster2)<<std::endl;//20
	std::cout<<sizeof(Moster3)<<std::endl;//20
	system("pause");

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值