Re: Symbol-agnostic cast using only type_info.
ADDENDUM:
The only other option is that all polymorphic types implicitly inherit
from a universal "object" base class. This is essentially how they are
implemented, anyway. At least with this option, one can use dynamic_cast
in the usual way, without any void * nastiness.
I would prefer this over direct_cast. Instead of "object", it could
be called "poly" and would introduce a new CSK (no more privileged
types in namespace std, please). It would just be the void * of polymorphic
types; one can only declare qualified pointers or references to a poly:
// Nice n' clean; no home-brewed base!
class maybe
{public: virtual ~maybe(){}};
poly p; // Illegal: Cannot instantiate a "poly".
poly *pptr = new maybe{}; // Look ma, no "any".
auto mptr = dynamic_cast<maybe *>(pptr); // Works!
The only reason this is a problem when implemented with current language
facilities is the existence of other base classes designed for exactly the
same purpose.
Wiring all polymorphic types into one standard base would eliminate the
"what base am I using" sort of coupling entirely.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]