[C++-sig] IndexError when returning pointer
Marcelo A. Camelo
camelo at esss.com.br
Tue Apr 15 23:08:45 CEST 2003
> It's got nothing to do with your problem,
> but it's usually bad form to use a cast
> (especially a C-style cast) when it's not
> needed.
Thank you for the reminder. But I do still need
it when exporting overloaded methods, don't I?
If so, I will make sure my bindings generator
only specify the cast when exporting overloaded
methods.
Greetings,
Marcelo A. Camelo, M. Eng. Project Leader
ESSS Engineering Simulation and Scientific Software
E-mail: camelo at esss.com.br
Phone: +55-48-239-2226
-----Original Message-----
From: c++-sig-admin at python.org [mailto:c++-sig-admin at python.org] On
Behalf Of Dave Abrahams
Sent: terça-feira, 15 de abril de 2003 11:23
To: c++-sig at python.org
Subject: Re: [C++-sig] IndexError when returning pointer
On Friday, April 11, 2003 3:25 PM [GMT+1=CET],
Marcelo A. Camelo <camelo at esss.com.br> wrote:
> Oops,
>
> I've made a terrible mess on the sample code
> I've sent on my last message. Sorry!!!
>
> Here is the correct version:
>
> struct foo
> {
> static foo* get_singleton() { return singleton; }
> static foo* singleton;
> };
>
> foo* foo::singleton = NULL;
>
> BOOST_PYTHON_MODULE( frog )
> {
> using namespace boost::python;
>
> class_< foo, boost::noncopyable >( "foo", no_init )
> .def( "get_singleton", (foo*(*)() )
^^^^^^^^^^^^
> &foo::get_singleton, return_internal_reference<>() ) .staticmethod(
> "get_singleton" ) ;
> }
>
>
> > > > import frog
> > > > a = frog.foo.get_singleton()
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> IndexError: tuple index out of range
It's got nothing to do with your problem, but it's usually bad form to
use a cast (especially a C-style cast) when it's not needed.
--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig
More information about the Cplusplus-sig
mailing list