4 ms·
C++ doesn't have the fragile base problem, as members aren't virtual my default. The only concern with unintended inheritance is with polymorhpic deletion. "fin
by leni536 2y ago
C++ doesn't have the fragile base problem, as members aren't virtual my default. The only concern with unintended inheritance is with polymorhpic deletion. "final" on class definition disables some tricks thag you can do with private inheritance.
Having said that "final" on member functions is great, and I like to see that instead of "override".
- pjmlp 2y agoAll OOP languages have it, the issue is related to changing the behaviour of the base class, and the change introducing unforceen consequences on the inheritance tree. Changing an existing method way of calling (regular, virtual, static), changing visibility, overloading, introducing a name that clashes downstream, introducing a virtual destructor, making a data member non-copyable,...
- leni536 2y ago> All OOP languages have it, the issue is related to changing the behaviour of the base class, and the change introducing unforceen consequences on the inheritance tree. C++ largely solves it by having tight encapsulation. As long as you don't change anything that breaks your existing interface, you should be good. And your interface is opt-in, including public members and virtual functions.
- pjmlp 2y agoNot when you change the contents of the class itself for public and protected inheritance members, which is exactly the whole issue of fragile base class. It doesn't go away just because private members exist as possible language feature.
- leni536 2y agoThat's not a fragile base, that's just a fragile class. You can break APIs for all kinds of users, including derived classes. Some APIs are aimed towards derived classes, like protected members and virtual functions, but that doesn't make the issue fundamentally different. It's just breaking APIs. Point is, in C++ you have to opt-in to make these API surfaces, they are not the default.
- pjmlp 2y agoI give up, word games to avoid acknowledging the same happens.
- jstimpfle 2y agoNow try a regular function, you will be blown away. No need to type "final"...