Use dyncast_or_null instead of dyncast .