[C++-sig] Raw constructor (i.e. combination of make_constructor and raw_function)

Hans Meine hans_meine at gmx.net
Wed Aug 24 18:28:20 CEST 2005


Hi again!

On Monday 22 August 2005 02:47, David Abrahams wrote:
> > I am trying to do something like
> >
> >     python::class_<MyVector>("PythonVector", python::no_init)
> >         .def("__init__", python::raw_function(&createVector, 1));
> >
> > But this gives the vector as first element of the args tuple to
> > createVector().
>
> What's wrong with that?

I now tried to make my problem as clear as possible by createing a short 
testcase module (which also contains some comments summarizing the most 
important stuff from my other posts).

# this works fine until..
from vector_testcase import *
v1 = createVector(1,2,3)
assert len(v1) == 3
v1[2]=42
# ..here. I cannot make the next line work:
v2 = Vector(1,2,3)

(I am getting: "TypeError: No registered converter was able to extract a C++ 
reference to type MyVector from this Python object of type Vector")
The ultimate goal is to make "pickle.dumps(v1)" work - if you see a way 
without having a working python constructor, that would be OK, too.

-- 
Ciao, /  /                                                    .o.
     /--/                                                     ..o
    /  / ANS                                                  ooo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vector_testcase.cxx
Type: text/x-c++src
Size: 2233 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20050824/98399132/attachment.cxx>


More information about the Cplusplus-sig mailing list