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

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