Consummating virtuality to support more polymorphism in C++

  • Authors:
  • Wen-Ke Chen;Jia-Su Sun;Zhi-Min Tang

  • Affiliations:
  • Institute of Computing Technology, Chinese Academy of Sciences;Institute of Computing Technology, Chinese Academy of Sciences;Department of Computer Science, Beijing University, Beijing 100871, P. R. China

  • Venue:
  • ACM SIGPLAN Notices
  • Year:
  • 1997

Quantified Score

Hi-index 0.00

Visualization

Abstract

Inheritance together with virtual functions in C++ provides programmers much polymorphism, an important facility of object-oriented design and programming. However, they can hardly be applied to enrich a family of classes (including the base classes and their derived classes) with some common features. Multiple inheritance and virtual base classes are usually hired to solve such a problem, or templates can also be employed for the same purpose. Unfortunately, these approaches are unnatural and costly. Moreover, virtual base classes deflect from the concept of dynamic binding behind virtual functions and therefore complicate the incomplete virtuality in C++. In this paper, we demonstrate that truly virtual base classes can be utilized to solve the problem effectively and efficiently, and can be used to express explicitly what virtual base classes do implicitly in a more flexible and lucid way. In addition, they along with virtual data members can provide further polymorphism and a type-safe and efficient alternative to constrained genericity and multiple inheritance in some cases, and hence facilitate the design and implementation of extensible and portable software, especially libraries of classes.