O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Inheritance and Polymorphism with C++

Video Description

Gain new control of your code through a clear understanding of inheritance and polymorphism in C++. Expert Jason Turner teaches you the basics, the gotchas, the implementation and optimization of polymorphism and inheritance through live coded demonstrations and hands-on exercises. To get the most out of the course, learners should already have a basic understanding of C++ programming.

  • Discover the differences between runtime and compile time polymorphism and how to combine them to create powerful constructs
  • Understand class hierarchies in C++
  • Learn to control aspects of a class using access specifiers
  • Explore covariant return types, multiple and virtual inheritance, private constructors, destructors, mixins, CRTP, and other advanced topics
  • Review the cost and optimization methods of polymorphism, as well as the trade-offs considered when designing libraries
  • Gain the ability to implement the std::any and std::function
Jason Turner has over 15 years of programming experience specializing in cross-platform development, scripting of C++ libraries, and automated testing and code quality analysis. Jason is the co-creator and maintainer of the embedded scripting language for C++, ChaiScript, and is the author and curator of the forkable coding standards document, C++ Best Practices. He has spoken at CppCon in Bellevue, Washington, C++Now in Aspen, Colorado, and, is the co-host of CppCast, the podcast for C++ developers. You can discover articles by Jason on his EmptyCrate.com blog.

Table of Contents

  1. Introduction
    1. What We Will Cover In This Video 00:02:26
    2. About The Author 00:02:06
    3. Compile Time Vs. Runtime Polymorphism 00:01:54
    4. Basics Of Inheritance 00:03:50
    5. Basics Of Templates 00:05:27
  2. Inheritance
    1. Access Specifiers 00:05:03
    2. Friends 00:03:13
    3. Nested And Local Class Access 00:03:18
    4. Virtual Functions And Abstract Base Classes 00:03:39
    5. Virtual Destructors 00:04:39
    6. Using Override And Final 00:05:20
    7. Exercise 1 - Chapter 2 - Object Factory 00:03:28
  3. Inheritance Gotchas
    1. Friendship Is Not Inherited Or Transitive 00:03:55
    2. Be Aware Of Slicing 00:04:30
    3. Understanding Overloading Vs Overriding 00:03:51
    4. Using The Using Declarations 00:03:55
    5. Exercise 1 - Chapter 3 - Clean Up Inheritance 00:03:05
    6. Exercise 2 - Chapter 3 - Fix The Error 00:02:01
  4. Inheritance - Advanced Topics
    1. Covariant Return Types 00:04:01
    2. Multiple Inheritance 00:05:04
    3. Virtual Inheritance 00:04:23
    4. Private Constructors 00:04:01
    5. Private Destructors 00:04:48
    6. Dynamic_Cast And Static_Cast 00:05:44
    7. Mixins And CRTP 00:03:02
    8. Implementating Pure Virtual Functions 00:02:13
    9. Exercise 1 - Chapter 4 - Creating A Mixin 00:05:18
    10. Exercise 2 - Chapter 4 - Fixing Up The Inheritance 00:05:10
  5. Polymorphism Cost And Optimization
    1. Cost Of Adding Virtual Functions 00:03:17
    2. Cost Of Virtual Function Calls 00:04:26
    3. Cost Of Virtual Destruction 00:05:32
    4. Avoid Template Bloat With Smart Pointers 00:04:59
    5. Empty Base Optimization 00:04:03
    6. Exercise 1 - Chapter 5 - Reduce Program Execution Cost 00:05:01
    7. Exercise 2 - Chapter 5 - Reduce Program Compiled Size 00:05:05
  6. Conclusion
    1. Best Practices Summary 00:03:10
    2. Type Erasure 00:03:38
    3. Function As Polymorphism 00:04:11
    4. Any And Union As Polymorphism 00:03:06
    5. Exercise 1 - Chapter 6 - Function Object 00:02:44
    6. Exercise 1 - Chapter 6 - Function Object Solution 00:05:17
    7. Exercise 2 - Chapter 6 - Any Implementation 00:02:38
    8. Exercise 2 - Chapter 6 - Any Implementation Solution 00:07:51
    9. Wrap Up And Thank You 00:01:34