Simulating polymorphic operators in C++

Research output: Contribution to specialist publicationArticle


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 languageEnglish (US)
Number of pages10
Specialist publicationDr. Dobb's Journal
StatePublished - Aug 1 2007

ASJC Scopus subject areas

  • Software
  • Computer Networks and Communications


Dive into the research topics of 'Simulating polymorphic operators in C++'. Together they form a unique fingerprint.

Cite this