Skip to main content

Polymorphism

  • Chapter
  • First Online:
Beginning C++17
  • 4828 Accesses

Abstract

Polymorphism is such a powerful feature of object-oriented programming that you’ll use it in the majority of your C++ programs. Polymorphism requires you to use derived classes, so the content of this chapter relies heavily on the concepts related to inheritance in derived classes that we introduced in the previous chapter.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 39.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    Some compilers don’t enable runtime type identification by default, so if this doesn’t work, look for a compiler option to switch it on.

  2. 2.

    With some popular compilers, we kid you not, you may even notice that typeid() evaluates its operand twice. In our example, that means that the line GetSomeBox() called... might appear twice in the output. This is a bug, of course. But still it’s all the more reason never to apply typeid() to a function call.

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2018 Ivor Horton and Peter Van Weert

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Horton, I., Van Weert, P. (2018). Polymorphism. In: Beginning C++17. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-3366-5_14

Download citation

Publish with us

Policies and ethics