[C++-sig] Extracting C++ objects of different types from a Python list

Roman Yakovenko roman.yakovenko at gmail.com
Wed Jun 27 09:58:24 CEST 2007


On 6/27/07, Craig Finch <oanjao at yahoo.com> wrote:
> I have run into a problem that I don't know how to solve with
> Boost.python, and I can't find the answer online.  I have a list of
> objects in Python, and the objects are of different classes.  All the
> classes are derived from a common base class, and the classes are
> defined in C++ and exposed to Python.  The list of objects is created
> in Python, and I would like to get this list into C++, where the the
> objects of different types will be handled differently.  I can bring
> the list into C++ as a boost::python::list, but then I have to use
> extract <type> to get the individual objects from the list.  The
> problem is that extract<baseclass> works, but then all of the extracted
> objects are the same type.  The information contained in the derived
> types is lost.

Try to extract "baseclass&".

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/



More information about the Cplusplus-sig mailing list