3 ms·
dynamic_cast downcasts in C++ only work across public inheritance. In particular a object that inheritance a Closable interface privately and a Reader interface
by nly 13y ago
dynamic_cast downcasts in C++ only work across public inheritance. In particular a object that inheritance a Closable interface privately and a Reader interface publicly wouldn't allow a cross cast.
dynamic_cast isn't a loophole in the type system, it's there to strengthen it.
- marshray 13y agoI don't think I've ever seen C++ that inherited an interface privately. That said, it's extremely common for classes to lack any virtual functions and thus be unusable with dynamic_cast.
- nly 13y agoWell protected is the default.
- pjmlp 13y agoThe default is private for classes and public for structs. Section 11.2 of the C++ standard.
- pjmlp 13y agoBy default it is private. Usually private inheritance is mostly used for library code, as a way for code reuse but without exposing the inheritance relationship to the class users. Also coupled with mixins sometimes.