Originally Posted by
stahta01
I have no idea what "type switching" is as it applies to C/C++ (I would guess related to casting).
Casting is part of it. More generally, it means to avoid writing code that overtly determines the type of an object, and does things differently depending on what the type is, such as
Code:
switch (object->type())
{
case object_type1:
((type1 *)object)->something_for_type1();
break;
case object_type2:
((type2 *)object)->something_for_type2();
break;
}
Instead use polymorphism (for example, a virtual do_something() member function in a base class that is overridden by each derived class). Once the polymorphic class is set up, the above can be done simply as
Code:
object->do_something(); // object is pointer to base, but actually may point to an instance of derived class