Casting pointers and the ternary ?: operator. Have I reinvented the wheel?
The last line of this code fails to compile with castingAndTernary.cpp:15: error: conditional expression between distinct pointer types ‘D1*’ and ‘D2*’ lacks a cast A really smart compiler could have no difficulty because both can be safely casted to B* (the base class). I'm reluctant to use static_cast and dynamic_cast and so on - I'm worried that I'll mix up the classes someday and get undefined behaviour. That's why I created the up_cast template. This template does the bare minimum in allowed conversion. Is there a simpler way? There are other workarounds, but I can't help but think that