4 ms·
> The bottom line is, no one ever really used inheritance that much anyway (other than smart people trying to outsmart themselves). Inheritance is most definit
by quietbritishjim 1y ago
> The bottom line is, no one ever really used inheritance that much anyway (other than smart people trying to outsmart themselves).
Inheritance is most definitely used in many popular C++ libraries, e.g., protobuf::Message [1] (which is base class to all user message classes and also has its own base class of MessageLite) or QWidget [2] (which sits in a large class hierarchy) or tinyxml2::XMLNode (base class to other node types). These are honestly the first three libraries that I thought of that have a non-trivial collection of classes in them. They're all stateful base classes by the way, not pure interfaces. And remember, I'm not trying to justify whether these are good or bad designs, just the make the observation that inheritance certainly is well used in practice.
(The fourth library I thought of with a reasonably complex collection of classes is Boost ASIO [4] which actually doesn't use inheritance. Instead it uses common interfaces to allow some compile-time polymorphism. Ironically, this is the only library in the list that I've been so unsatisfied with that I've written my own wrapper more than once for a little part of it: allowing auto-(re)connecting outbound and accepting incoming connections with the same interface. Guess what: I used inheritance!)
[1] https://protobuf.dev/reference/cpp/api-docs/google.protobuf.message/#Message https://protobuf.dev/reference/cpp/api-docs/google.protobuf....
[2] https://doc.qt.io/qt-6/qwidget.html https://doc.qt.io/qt-6/qwidget.html
[3] https://leethomason.github.io/tinyxml2/classtinyxml2_1_1_x_m_l_node.html https://leethomason.github.io/tinyxml2/classtinyxml2_1_1_x_m...
[4] https://www.boost.org/doc/libs/1_88_0/doc/html/boost_asio/reference.html https://www.boost.org/doc/libs/1_88_0/doc/html/boost_asio/re...