[C++-sig] Instantiate a wrapped class in C++ and get the PyObject pointer

Stefan Seefeld seefeld at sympatico.ca
Mon Apr 23 22:11:15 CEST 2007


David Sveningsson wrote:

> My question is how to instantiate a wrapped class and get the PyObject 
> pointer. Do I need to know the type of the class to convert it or could 
> I write a general toPython method that would work on many classes?

class_<A> a_type(...); // Define the mapping (and implied conversion operator)
// ...

object a_instance = A(...); // Create an A instance and wrap it in a python object

PyObject *ptr = a_instance.ptr(); // access a C API pointer from the instance

Is that all you want ?

HTH,
		Stefan

-- 

      ...ich hab' noch einen Koffer in Berlin...



More information about the Cplusplus-sig mailing list