How can I tell the inheriting class to not call its base class' parameter-less constructor?

前端 未结 7 2729
礼貌的吻别
礼貌的吻别 2021-02-19 23:32

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

7条回答
  •  粉色の甜心
    2021-02-20 00:20

    You could make the default base constructor protected, then have only non-default constructors for the base and its child.

    edit

    You could give the base a protected constructor with a different signature (such as a protected enum type), and put your initialization code in there, while the default constructor, also protected, does not particular initialization.

提交回复
热议问题