Skip to search boxSkip to navigationSkip to main content

Simulating polymorphic operators in C++

*Corresponding author for this work
Scholary Output:
Contribution to specialist publication
Article
Research

Abstract

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.

Publication Information

Output type

Scholary Output:
Contribution to specialist publication
Article
Research

Original language

English (US)

Pages from-to (Number of pages)

Pages 46-55 (10 pages)

Journal (Volume, Issue Number)

Dr. Dobb's Journal (Volume 32)

Publication milestones

  • Published - 08/2007

Publication status

Published - 08/2007

ISSN

1044-789X

Publication IDs

  • Scopus: 34547423811

Publication metrics

Metrics

SciVal
Author count
1
SciVal
Paper percentile
25
Fractional count
1
Fractional count
1
Fractional count
1
Fractional count
1