
27 Jul
2011
27 Jul
'11
9:06 a.m.
I have three C++ classes X, Y and Z that I have exported from C++ to Python using python::class_. Now I want to write a factory function like PyObject* f(char c) { if(c == 'x') return new X; else if(c == 'y') return new Y; else if(c == 'z') return new Z; else PyErr_SetString(PyExc_ValueError, "Bad function argument"); } and export that function to Python. What is missing here is code that converts X*, Y* and Z* to PyObject*. How do I write that? Thank you, Johan