[C++-sig] How to add an __init__ function ?

Pierre Barbier de Reuille pierre.barbier at cirad.fr
Wed Sep 17 12:27:55 CEST 2003


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 ...

-- 
Pierre Barbier de Reuille

INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
Botanique et Bio-informatique de l'Architecture des Plantes
TA40/PSII, Boulevard de la Lironde
34398 MONTPELLIER CEDEX 5, France

tel   : (33) 4 67 61 65 77    fax   : (33) 4 67 61 56 68 






More information about the Cplusplus-sig mailing list