I have a class structure like
abstract class Animal {
public Animal(){
//init stuff..
}
}
class Cat : Animal {
public Cat(bool is_keyboard) : base() //NOTE here
{
//other init stuff
}
}
Now then, look at the noted line. If you remove : base() then it will compile without an error.
Why is this? Is there a way to disable this behavior?
There is an implicit
: base()if you don’t add anything else (any: base(...)or: this(...)). To force it to be explicit, add a parameter to the base-constructor(s). Then it can’t be implicit.For example: