[C++-sig] Re: operator[]

David Abrahams david.abrahams at rcn.com
Wed May 22 19:32:36 CEST 2002


You can't return an internal reference to an object which isn't of class
type (a double in this case). C++ doubles are converted to Python floats by
copying; there's no Python type which can hold a reference to the
internally-held double. return_value_policy<copy_non_const_reference> is
your friend in this case.

-Dave

----- Original Message -----
From: "chuzo okuda" <okuda1 at llnl.gov>
To: <c++-sig at python.org>
Sent: Wednesday, May 22, 2002 1:21 PM
Subject: Re: [C++-sig] Re: operator[]


> Greeting Martin,
> You are right, but I got different error this time...
>
> I added:
>
> #include <boost/python/return_internal_reference.hpp>
> and added
> return_internal_reference<>()
> to the line becoming:
> .def("__getitem__", (double& (Vector2d::*)(const
> int))&Vector2d::operator[],return_internal_reference<>())
>
> and I get:
>
>
"/usr/dnta/kull/developers/thirdPartySoftware/boost-chuzo/boost/boost/pytho
n/to_python_indirect.hpp",
> line 66: error:
>           incomplete type is not allowed
>             BOOST_STATIC_ASSERT(is_class<T>::value);
>
> :-(
> Chuzo







More information about the Cplusplus-sig mailing list