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
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsNotes
- 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.
SOR is an iterative technique for solving linear systems: see, for example, Iserles [1].
- 3.
The advanced programmer can test if a Guest is a SpecialGuest using a feature called dynamic casting.
References
Mathematical Methods and Linear Algebra
Iserles, A.: A First Course in the Numerical Analysis of Differential Equations, 2nd edn. Cambridge University Press, Cambridge (2009)
Kreyszig, E.: Advanced Engineering Mathematics, 9th edn. Wiley, New York (2006)
Author information
Authors and Affiliations
Corresponding author
Rights and permissions
Copyright information
© 2012 Springer-Verlag London Limited
About this chapter
Cite this chapter
Pitt-Francis, J., Whiteley, J. (2012). Inheritance and Derived Classes. In: Guide to Scientific Computing in C++. Undergraduate Topics in Computer Science. Springer, London. https://doi.org/10.1007/978-1-4471-2736-9_7
Download citation
DOI: https://doi.org/10.1007/978-1-4471-2736-9_7
Publisher Name: Springer, London
Print ISBN: 978-1-4471-2735-2
Online ISBN: 978-1-4471-2736-9
eBook Packages: Computer ScienceComputer Science (R0)