0

I know how Polymorphism works, but I am trying to understand in what cases is Polymorphism useful.

Now All the examples that I have found about Polymorphism are one of the following (the below code is in C++):

  • Either we have an array of type Base* that holds pointers to objects derived from the Base class, and then we loop through the array and call something like Base->foo()

  • Or we have a function that have a Base* parameter, and then we call this function and pass it a pointer to any of the objects derived from the Base class

Are these the only cases where Polymorphism is useful?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.