Sort objects and polymorphism
- by ritmbo
Suppose I have a class A.
And B and C are child of A.
Class A has a generic algorithm for sorting arrays of type A, so that I could use it for B and C without writing again the algorithm for each.
In the algorithm, sometimes I have to swap.
The problem is that I can only see the objects as type A, and if I do:
A aux = array[i]
array[i] =…