[C++-sig] Re: Extracting C++ objects: documentation example fails.
Mike Rovner
mike at nospam.com
Sat Oct 25 00:33:51 CEST 2003
Joel Gerard wrote:
> I'm trying to extract some wrapped objects from a python script in
> C++. I've tried running the example from the docs to see how extract
> works, but it wont compile:
>
> struct X
> {
> X(int x) : v(x) {}
> int value() { return v; }
> private:
> int v;
> };
>
> foo()
> {
> object x_class(
> class_<X>("X", init<int>())
> .def("value", &X::value))
> ;
>
> // Instantiate an X object through the Python interface.
> // Its lifetime is now managed by x_obj.
> object x_obj = x_class(3);
>
> // Get a reference to the C++ object out of the Python object
> X& x = extract<X&>(x_obj);
> assert(x.value() == 3);
Extract means smthng different, e.g. extracting a value
int x = extract<int>(x.obj.attr("value"));
> I'm using VC 7.
Don't! Use VC7.1
HTH,
Mike
More information about the Cplusplus-sig
mailing list