[C++-sig] polymorphic object handling
Burkhard Doliwa
doliwa at temf.tu-darmstadt.de
Tue Aug 2 13:06:35 CEST 2005
Hi all,
I have a problem wrapping a factory function to python. I have two
abstract base classes A,B, with some child classes
A<-A1,A2,A3
B<-B1,B2,B3
every child class is either able to clone itself or to return an
instance of the corresponding "parallel class", i.e.
A* A1::cloneA() const yields an A1
B* A1::cloneB() const yields an B1
A* B2::cloneA() const yields an A2
B* B2::cloneB() const yields an B2
and so forth. The factory function
object factoryA(const A&, bool isA) {
return isA? object(A.cloneA()) : object(A.cloneB());
}
only returns python objects of the base class types, not the derived
classes, i.e.
>>> a1=A1()
>>> factory(a1,True)
result= A object (NOT an A1 object)
How could I create the correct derived class in such a conditional
factory function (like the return_value_policy<manage_new_object>() case)?
Thanks,
Burkhard
More information about the Cplusplus-sig
mailing list