Your example won't port, because the exact format of name() isn't specified. You could try a succession of dynamic_cast
s. Dynamic_cast
returns a null pointer if you cast to the wrong type. However, if you're doing a typeswitch like this one, there's something wrong with your design.