[C++-sig] Re: iterators and abstact base class
David Abrahams
dave at boost-consulting.com
Wed Mar 10 20:29:17 CET 2004
Francois Ostiguy <ostiguy at fnal.gov> writes:
> Sorry for not being specific enough. This is really a boost.python
> question. The iterator is a custom iterator (the code was written
> in the early 1990s) which returns a pointer to the base class.
> Of course, the object returned is always an instance of a derived class.
> So if class C is my container class and next is the "iterator"
>
> class A; // abstract class
> class B: public A {
> ...
> };
>
> C c; // container class, contains objects instances of
> // classes derived from A
> ...
>
> Iterator i(c);
>
> A* a = i. next(); // generic way to retrieve the next element in the
> container
> a.function(); // calls a virtual function on the element
Surely it's a->function();
??
> I want to achieve in python
>
> b1 = B(..) # appropriate contructor
> b2 = B(..) #
> c = C(b1, b2) # constructs a C which contains b1 and b2
> i = I(c) # i is an iterator for c
>
> a = i.next() <<<<==== this is the problem. i.next() must return something
> that can be held into python object a. In C++
> i.next() returns a type A*.
>
> a.function()
>
> ...
>
> How do I define a python type that can be used to hold what i.next() returns ?
I don't understand the problem. Why not wrap "A" using class_; then
wrap next() with reference_existing_object or another appropriate call
policy?
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list