The several ways of making insertion and extraction operators polymorphic in C++ are discussed. The simplest version accomplishes the polymorphic behavior by adding extra virtual methods to each class. These new items are methods and can be polymorphic, while the operators are nonmember functions. The space required for the version is the memory for the class's vtable plus memory for a pointer in each and every object. The next version removes the extra virtual methods of the first version to reduce the memory requirements of the program while keeping the performance levels the same. This version includes the simulation of the desired polymorphism by using the C++ runtime_type_information (RTTI) feature combined with the dynamic_cast operator within the parent's insertion function. The final version replaces the dynamic_cast operator with a type identifier added to the parent class, while no virtual method is needed in any of the class.
|Original language||English (US)|
|Number of pages||10|
|Specialist publication||Dr. Dobb's Journal|
|State||Published - Aug 1 2007|
ASJC Scopus subject areas
- Computer Networks and Communications