我有一个基类和 2 个派生类。基类有一些简单的受保护浮点变量,我的基类的构造函数如下:
public Enemy(float _maxhp, float _damage)
{
maxhp = _maxhp;
health = _maxhp;
damage = _damage;
}
但是,我的派生类Range还有 2 个浮点变量attack and attackSpeed需要在创建新实例时作为参数传入,Range但我似乎无法做到这一点,因为There is no argument that corresponds to the required formal parameter '_maxhp' of 'Enemy.Enemy(float, float)'当我尝试使用派生的构造函数时出现错误提示具有这些参数的类:
public Range(float _maxhp, float _damage, float _attack, float _attackSpeed)
但是具有相同数量参数的构造函数可以工作
public Range(float _maxhp, float _damage)
为什么会发生这种情况,是否有某种解决方法?提前致谢。