[C++-sig] error in argument conversion

Stefan Seefeld seefeld at sympatico.ca
Sun Jan 23 04:11:04 CET 2005

I'v run into a runtime error which I found no explanation for.
Here is what I'm doing in python:

 >>> type(ptree)
<class 'PTree.List'>
 >>> ptree.car()
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
Boost.Python.ArgumentError: Python argument types in
did not match C++ signature:

where 'PTree.List' is a python wrapper around my class, which I generate so:

Node *car(List *l) { return l->car();}
Node *cdr(List *l) { return l->cdr();}

   bpl::class_<Node, bpl::bases<>, Node *, boost::noncopyable> node("Node", bpl::no_init);
   bpl::class_<List, bpl::bases<Node>, List *, boost::noncopyable> list("List", bpl::no_init);
   list.def("car", car, bpl::return_value_policy<bpl::reference_existing_object>());
   list.def("cdr", cdr, bpl::return_value_policy<bpl::reference_existing_object>());

I don't quite understand the text in the 'ArgumentError' exception.
It suggests the python type 'List' couldn't be converted to the C++ type 'PTree::List*'.
Is that interpretation correct ? If so, what possible reasons exist for the requested
conversion to fail, given the above definition of the wrapper class ?


PS: the reason I expose raw pointers and use the above return value policy is
     that these PTree classes all use a garbage collector library.

More information about the Cplusplus-sig mailing list