Re: Inheriting nested classes (iterators)
Martin wrote:
I have two classes that implements 3D point clouds: M and S. I want
both classes to implement an iterator to iterate over the points
contained in each object, and have a points() method to give a pair of
iterators to the first and the past-the-end element, like this:
std::pair< M::Point_Iterator, M::Point_Iterator > M::points();
std::pair< S::Point_Iterator, S::Point_Iterator > M::points();
I would seem that you made a copy-and-paste mistake here. Don't you
mean
std::pair< M::Point_Iterator, M::Point_Iterator > M::points();
std::pair< S::Point_Iterator, S::Point_Iterator > S::points();
?
The iterator implementation needs to be different, since the classes
store the points in quite different ways. But algorithms working with
point clouds should work with both classes.
How should I do this? I can use common inheritance from a base class
(B) for all other shared methods, of course, but you can't have
virtual nested classes, right?
What use would "virtual nested classes" have? What problem could
you solve with it/them?
If you go with the base class member, you will have to put the
type 'Point_Iterator' in the base class as well. Not sure if you
can do that, nor what problems you're going to have to work around
if you try to massage your 'B' into having that type.
I hope my question is understandable.
Not fully, but maybe it's just me.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask