Boost logo

Boost :

From: David Rostowsky (davros1_at_[hidden])
Date: 2004-03-31 10:25:08

I have a couple of really simple classes:

class MyBase
  int x;
  virtual int foo(int new_x) { }; // our derived classes may or may not override this function. Coders choice.

class MyDerived: public MyBase
  int y;
  MyDerived() { y = 0; };
  int Get(void) { return y; };
  void Set(int val) { y = val; };

My main goal in life is to create an instance of MyDerived class in C++:
MyDerived my_derived = new MyDerived();

and then pass the pointer to a Python script where the Python script can call any of the public member functions. Yes, I am careful to keep the pointer around in the C++ code while the Python script uses it. So I expose the class (this may or may not be the source of my problems, need help):

    using namespace boost::python;

        .def("Get", &MyDerived::Get)
        .def("Set", &MyDerived::Set)
} /* test*/

My impasse is that the virtual function seems to really give Boost hell when Im trying to pass the pointer to the class over to the python script. Heres the code snippet for that. Its the conversion thats just KILLING me. If I comment out the virtual function, everything works perfectly! I can pass the pointer over to my script, it calls the public member functions, and Im happy. HOWEVER, if I put the virtual function back in, the following line of code just EXPLODES!

// It crashes and burns in make_ptr_instance.cpp, function get_derived_class_object()
boost::python::object my_arg(boost::ref(my_derived));

// pass the pointer over to the script now.
int rval = callPython("myTestFunc", "Test String argument from c++", my_arg);

Im completely frustrated by this. I need some psychological help!

Thanks in advance!


Boost list run by bdawes at, gregod at, cpdaniel at, john at