Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Inheriting nested classes (iterators)

Reply
Thread Tools

Inheriting nested classes (iterators)

 
 
Martin
Guest
Posts: n/a
 
      01-21-2008
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:air< M:oint_Iterator, M:oint_Iterator > M:oints();
std:air< S:oint_Iterator, S:oint_Iterator > M:oints();

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?

I hope my question is understandable.
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      01-21-2008
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:air< M:oint_Iterator, M:oint_Iterator > M:oints();
> std:air< S:oint_Iterator, S:oint_Iterator > M:oints();


I would seem that you made a copy-and-paste mistake here. Don't you
mean

std:air< M:oint_Iterator, M:oint_Iterator > M:oints();
std:air< S:oint_Iterator, S:oint_Iterator > S:oints();

?

> 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


 
Reply With Quote
 
 
 
 
Martin
Guest
Posts: n/a
 
      01-21-2008
On 21 Jan, 13:24, Martin <(E-Mail Removed)>
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:air< M:oint_Iterator, M:oint_Iterator > M:oints();
> std:air< S:oint_Iterator, S:oint_Iterator > M:oints();
>
> 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?
>
> I hope my question is understandable.


In essence, what I want is a base class B with derived classes M and
S, and a B::iterator that can be used both with M and S, even though
their iterator implementations are different. Is that at all possible?
 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      01-21-2008
Martin wrote:
> On 21 Jan, 13:24, Martin <(E-Mail Removed)>
> 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:air< M:oint_Iterator, M:oint_Iterator > M:oints();
>> std:air< S:oint_Iterator, S:oint_Iterator > M:oints();
>>
>> 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?
>>
>> I hope my question is understandable.

>
> In essence, what I want is a base class B with derived classes M and
> S, and a B::iterator that can be used both with M and S, even though
> their iterator implementations are different. Is that at all possible?


Yes. The iterator will have to have a base portion and the "derived"
portion, most likely of the PIMPL kind. Essentially, you will have to
make your derived classes provide the iterator's "derived" portion,
and any functionality in 'B::iterator' will have to be implemented
through the transparent to the user 'B::iterator_impl', polymorphically.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem inheriting nested class.. Wolfgang C++ 2 11-11-2007 12:07 PM
Nested Vector Nester Classes are Nested in my Brain Chad E. Dollins C++ 3 11-08-2005 04:46 AM
Nested classes within other classes Tony Johansson C++ 2 12-14-2004 11:41 AM
Nested Classes vs Top-Level Classes kelvSYC Java 2 08-18-2004 07:09 AM
What is the difference between nested classes and inner classes ? Razvan Java 5 07-27-2004 07:59 PM



Advertisments