Helper for switching on object type in C++