I was surprised to find out that the parameter-less constructor of my base class is called any time I call any constructor in a derived class. I thought that is what
As others have pointed out, a derived instance must call call one of its base class' constructors.
If you want to control the execution of a base class' initialization logic, remove its default constructor and replace it with something like this:
public class Base {
// Base has no default constructor
public Base(bool initialize) {
if (initialize) {
// ... logic here
}
}
}
And the derived constructors look like this:
// Derived1 executes the initialization logic
public Derived1(): base(true) {}
// Derived2 does not
public Derived2(): base(false) {}