Hello, here's today's dilemma:
suppose I've
class A{
public:
virtual void doit() = 0;
}
then various subclasses of A, all implementing their good doit method. Now suppose I want to write a function that takes two iterators (one at the beginning of a sequence, the other at the end). The sequence is a sequence of A subclasses like say list<A*>
or vector... The function should call all the doit methods while scanning the iterators... How to do this? I've thought of:
template<typename Iterator> void doList(Iterator &begin, Iterator &end) {
for (; begin != end; begin++) {
A *elem = (serializable*) *begin;
elem.doIt();
}
}
but gives weird errors... do you have better ideas or specific information? Is it possible to use list<A>
instead of list<A*>
?