Skip to Content
C++ Templates: The Complete Guide, 2nd Edition
book

C++ Templates: The Complete Guide, 2nd Edition

by David Vandevoorde, Nicolai M. Josuttis, Douglas Gregor
September 2017
Intermediate to advanced
822 pages
26h 51m
English
Addison-Wesley Professional
Content preview from C++ Templates: The Complete Guide, 2nd Edition

Chapter 22

Bridging Static and Dynamic Polymorphism

Chapter 18 described the nature of static polymorphism (via templates) and dynamic polymorphism (via inheritance and virtual functions) in C++. Both kinds of polymorphism provide powerful abstractions for writing programs, yet each has tradeoffs: Static polymorphism provides the same performance as nonpolymorphic code, but the set of types that can be used at run time is fixed at compile time. On the other hand, dynamic polymorphism via inheritance allows a single version of the polymorphic function to work with types not known at the time it is compiled, but it is less flexible because types must inherit from the common base class.

This chapter describes how to bridge between static and dynamic ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C++ Software Design

C++ Software Design

Klaus Iglberger

Publisher Resources

ISBN: 9780134778808