Simulating polymorphic operators in C++

Research output: Contribution to specialist publicationArticle

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.

Original languageEnglish (US)
Pages46-55
Number of pages10
Volume32
No8
Specialist publicationDr. Dobb's Journal
StatePublished - Aug 1 2007

Fingerprint

Data storage equipment
Mathematical operators
Polymorphism

ASJC Scopus subject areas

  • Software
  • Computer Networks and Communications

Cite this

Simulating polymorphic operators in C++. / Dowell, Michael L.

In: Dr. Dobb's Journal, Vol. 32, No. 8, 01.08.2007, p. 46-55.

Research output: Contribution to specialist publicationArticle

@misc{b62a3870776b4b05b180b777a43cc4ba,
title = "Simulating polymorphic operators in C++",
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.",
author = "Dowell, {Michael L}",
year = "2007",
month = "8",
day = "1",
language = "English (US)",
volume = "32",
pages = "46--55",
journal = "Dr. Dobb's Journal",
issn = "1044-789X",
publisher = "CMP Media LLC",

}

TY - GEN

T1 - Simulating polymorphic operators in C++

AU - Dowell, Michael L

PY - 2007/8/1

Y1 - 2007/8/1

N2 - 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.

AB - 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.

UR - http://www.scopus.com/inward/record.url?scp=34547423811&partnerID=8YFLogxK

UR - http://www.scopus.com/inward/citedby.url?scp=34547423811&partnerID=8YFLogxK

M3 - Article

AN - SCOPUS:34547423811

VL - 32

SP - 46

EP - 55

JO - Dr. Dobb's Journal

JF - Dr. Dobb's Journal

SN - 1044-789X

ER -