I would like to be able to create a Python class derived from a C++ class, then pass a instance of the Python class back to C++. It isn't clear to me if there is an easy way to do this.

Here is a simple example of what I wish worked, but doesn't:

C++ side:

#include <boost/python.hpp>
#include <iostream>
class Foo
{
public:
    Foo(){};
    virtual void
    doit(){std::cout << "doing it Foo style\n";};
};
void
foodoer(Foo & foo)
{
    foo.doit();
}
using namespace boost::python;
BOOST_PYTHON_MODULE(foo)
{
    class_<Foo >("Foo", init<>())
            .def("doit", &Foo::doit);
    def("foodoer", foodoer);
}

Python side:

import foo
class Bar(foo.Foo):
    def __init__(self):
        pass
    def doit(self):
        print "doing it bar style"

f = foo.Foo()
# next line works
foo.foodoer(f)

b = Bar()
# next line does not work
foo.foodoer(b)


Does anyone have any advice for me?

Thanks,
Jim Amundson

_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to