[C++-sig] Re: iterators and abstact base class
dave at boost-consulting.com
Tue Mar 9 23:34:53 CET 2004
Francois Ostiguy <ostiguy at fnal.gov> writes:
> Hi -
> This has to be an FAQ. I searched the list archives and I was not able
> locate a satisfactory solution to the following problem:
> Assume an abstract base class A and a derived class B. I have an iterator
> I for a container C holding B-type objects. The iterator returns a
> pointer to the base class A.
> At runtime, I.next()
?? This is a standard C++ iterator, or something else??
> returns a type A which cannot be instantiated.
Clearly it can't return A; it can return a reference to A, though.
> I would like to iterate through my container and call a (virtual) function
> on each element. Can you point me to an idiom/technique that would
> allow me to accomplish this ?
Is this a Python/C++ question, a straight C++ question, or something
else? Too many details are missing.
More information about the Cplusplus-sig