Skip to main content

Inheritance and Derived Classes

  • Chapter
  • First Online:
  • 215k Accesses

Part of the book series: Undergraduate Topics in Computer Science ((UTICS))

Abstract

Suppose we have developed a class for a specific application. If we want to extend the software based on this class to do something slightly different we could modify the class already written. This, however, may not be an ideal solution as we may introduce conflicts with the functionality of the original class. A more suitable approach is to derive a new class that has the features of the original class (modified if required) together with any new features required. This is known as inheritance, and is a very powerful feature of the C++ language. One particularly useful feature of inheritance is that of polymorphism: we may apply the same functionality to instances of both the original class and the derived class, with the correct operations “under the hood” being chosen by the computer based on whether the instance of the class is the original or derived class.

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

Buying options

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
Softcover Book
USD   54.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Notes

  1. 1.

    A feature of C++ is that it also allows multiple inheritance, not available in other object-oriented languages, where derived classes may inherit from more than one base class. This feature causes some seasoned C++ programmers difficulty, and hence is beyond the scope of this book, although we do briefly discuss this topic in Appendix B.

  2. 2.

    SOR is an iterative technique for solving linear systems: see, for example, Iserles [1].

  3. 3.

    The advanced programmer can test if a Guest is a SpecialGuest using a feature called dynamic casting.

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Joe Pitt-Francis .

Rights and permissions

Reprints and permissions

Copyright information

© 2017 Springer International Publishing AG, part of Springer Nature

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Pitt-Francis, J., Whiteley, J. (2017). Inheritance and Derived Classes. In: Guide to Scientific Computing in C++. Undergraduate Topics in Computer Science. Springer, Cham. https://doi.org/10.1007/978-3-319-73132-2_7

Download citation

  • DOI: https://doi.org/10.1007/978-3-319-73132-2_7

  • Published:

  • Publisher Name: Springer, Cham

  • Print ISBN: 978-3-319-73131-5

  • Online ISBN: 978-3-319-73132-2

  • eBook Packages: Computer ScienceComputer Science (R0)

Publish with us

Policies and ethics