[C++-sig] Re: How to add an __init__ function ?
Mike Thompson
mike.thompson at day8.com.au
Wed Sep 17 14:28:38 CEST 2003
"Pierre Barbier de Reuille" wrote:
> I want to add an init function which is not a contructor of the original
> class. I export a C++ container and I want to be able to import any
> sequence object, so I created a (working) function
> "from_list(Container*, boost::pyhon::object obj)" which iterates over
> every elements of obj if an iterator can be created. But, if I define
> the '__init__' function with:
>
> .def ("__init__", from_list)
> .def(init<>())
>
> And I try this in python:
>
> >>> Container([1,2,3])
>
> I get the error:
> """
> Boost.Python.ArgumentError: Python argument types in
> Container.__init__(Container, list)
> did not match C++ signature:
> __init__(_object*)
> __init__(Container*, boost::python::api::object)
> __init__(_object*)
> """
>
> It seems to me that the second __init__ method just should be ok ...
>
AIUI, David Abrahams refers to these as "injected constructors" and they're not
possible right now.
See the TODO list item:
http://boost-consulting.com/boost/libs/python/todo.html#injected-constructors
Then again, their implementation might be available sometime soon-ish because,
when viewed through gmane.comp.python.c++, in the thread immediately preceding
this one, David explains that he has begun work on the potentially sweeping
changes involved in this TODO item. See the thread with subject
"[Implementation] Calling wrapped functions, converters,policies"
--
Mike
More information about the Cplusplus-sig
mailing list