From the course: Object-Oriented Programming with C++
Unlock this course with a free trial
Join today to access over 24,400 courses taught by industry experts.
Multiple inheritance - C++ Tutorial
From the course: Object-Oriented Programming with C++
Multiple inheritance
- [Instructor] So far, our classes have inherited from a single base class. However, C++ allows a class to inherit from multiple base classes. Let me show you why this might be useful, and also, why it needs to be used carefully. Let's extend our review system. Imagine we want our product review to also have social media features, likes, shares, comments. We should create a sociable class like the following. The class exposes public methods that allow users to like, share, comment, and display social media stats. Now, we can make product review inherit from both review and sociable. The syntax for multiple inheritance is simple. Just add a comma, followed by the inheritance access specifier, and the new class from which we want to inherit. But first, we need to include its header. Next, we'll call the displaySocialStats method of the sociable-based class from displayDetails. In the main function, we can use the new features. Let's add some social interactions. We'll call the like…
Contents
-
-
-
-
-
Why reinvent the wheel?3m 12s
-
(Locked)
Extending classes4m 37s
-
(Locked)
Access control in inheritance4m 1s
-
(Locked)
Overriding and extending functionality2m 11s
-
(Locked)
Multiple inheritance2m 22s
-
(Locked)
Multiple inheritance pitfalls6m 32s
-
(Locked)
Challenge: RPG character system2m 25s
-
(Locked)
Solution: RPG character system1m 35s
-
-
-
-