Typically, a C ++ way of writing algorithms that execute in a list, sequence, ... is to provide iterators as arguments.
template < class iterator > doSomething(iterator beg, iterator end);
This solves the list <Button *> is not removed from the <Control *> list. (using the List <T *> template too, but this kind of creating your common function, but not really)
In my experience, creating good template functions that work on iterators can be very large (too many ...), but this is a "C ++ way" ...
If you are following this route, consider using Boost.ConceptCheck . It will make your life a lot easier.
Pieter
source share