[C++-sig] iterators and abstact base class
Francois Ostiguy
ostiguy at fnal.gov
Tue Mar 9 22:17:08 CET 2004
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() returns a type A which cannot be instantiated.
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 ?
As always, any help is greatly appreciated.
-Francois
----------------------------------------------------------------------------
Dr. Jean-Francois OSTIGUY voice: (630) 840-2231
Beam Physics Dept MS220 FAX: (630) 840-6039
Fermi National Accelerator Laboratory email: ostiguy at fnal.gov
Batavia IL 60510-0500 WWW:www-ap.fnal.gov/~ostiguy
More information about the Cplusplus-sig
mailing list