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
One way would be to make your base default constructor private, but that only works if you make a helper constructor in the base class that calls the private one when you need it explicitly.
class Base
{
private Base() { ... special default base logic ... }
protected Base(... params ...) : this() { ... exposed base that calls private cons ... }
protected Base(... other params ...) /* no default call */ { ... exposed cons that doesnt call default ...}
}
class DerivedNoCall
{
public DerivedNoCall() : base(... other params ...) {} //<-- will NOT call default base
}
class DerivedDoCall
{
public DerivedDoCall() : base(... params ...) {} //<-- WILL call default base cons indirectly
}
This is really contrived, and @aakashm has the best answer.