From the course: Object-Oriented Programming with C++
Unlock this course with a free trial
Join today to access over 24,500 courses taught by industry experts.
The many faces of objects - C++ Tutorial
From the course: Object-Oriented Programming with C++
The many faces of objects
- [Instructor] Let's talk about one of the most powerful features in object-oriented programming, polymorphism. The word comes from Greek, meaning many forms, but how does this apply to C++ programming? Let's go back to our review system. So we have a base review class and specialized versions like product review and restaurant review. Imagine we're building a review management system that needs to calculate average ratings across different sections of the platform. So we'd write a function like calculate average rating, it takes two input parameters, a vector of product review objects, and another vector of restaurant review objects. We could process each of these vectors separately to calculate the average rating and finally return the result. And here's how we would use it. In the main function, we create two vectors for each specific review subclass. We then create product review and restaurant review objects, adding them to the corresponding vectors. Finally, we calculate the…
Contents
-
-
-
-
-
-
(Locked)
The many faces of objects3m 22s
-
(Locked)
Virtual functions: The basics2m 32s
-
(Locked)
Runtime polymorphism4m 33s
-
(Locked)
Pure virtual functions and abstract classes2m 7s
-
(Locked)
Virtual destructors: Why, when, and how6m 27s
-
(Locked)
Challenge: Superhero ability system1m 58s
-
(Locked)
Solution: Superhero ability system2m 16s
-
(Locked)
-
-