[C++-sig] Problem injecting Python __init__ into wrapped C++ class

Craig Finch oanjao at yahoo.com
Wed May 2 00:42:38 CEST 2007


Injecting Python methods into wrapped Boost C++ classes sounds like an
excellent idea.  It is described in the Boost.python tutorial at
http://www.boost.org/libs/python/doc/tutorial/doc/html/python/techniques.html#python.extending_wrapped_objects_in_python

I have been able to get this to work for ordinary methods, but I would
like to define an __init__ method in Python for a wrapped C++ class.  I
have created a test case, following the methods in the Tutorial, that
demonstrates the runtime error that results when I try this.  Because
this involves creating a Python package with a directory structure that
would be difficult to reproduce correctly in this message, I'm posting
a link to a .tgz file that contains everything you need to build and
run the example (using make and gcc) and see the error message.

http://www.shocksolution.com/files/TestConstructors.tgz

When I build and run the code, I get the following output:
----------------------------------------------------------
Python value is 18
C++ value is 18
Python value is
Traceback (most recent call last):
  File "TestConstructors/TestConstructors.py", line 8, in ?
    print "Python value is", y.value()
Boost.Python.ArgumentError: Python argument types in
    python_constructor.value(python_constructor)
did not match C++ signature:
    value(python_constructor {lvalue})

I would appreciate it if someone could take a look at the code (it's
really very small) and tell me what I'm doing wrong here.

--------------
Please reply to cfinch at ieee.org

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Cplusplus-sig mailing list