[C++-sig] Re: Boost.Python : Byref parameters

David Abrahams dave at boost-consulting.com
Fri Sep 26 23:05:45 CEST 2003


"Mike Rovner" <mike at nospam.com> writes:

> Joel Gerard wrote:
>
>> .def("Normalize",VectorNormalize1)
>> .def("Normalize",VectorNormalize2)
>> .def("Normalize",VectorNormalize3)
>
> You have to say .staticmethod("Normalize")

Well, except he has a static method overloaded with a non-static one,
and Boost.Python doesn't really support that idiom
(see thread at
http://aspn.activestate.com/ASPN/Mail/Message/C++-sig/1811696). I
suggest forgoing instance-less access for the static method as
follows:

  f32 nonstatic_Normalize(Vector&, Vector& kV) { return Vector::Normalize(kV); }


    .def("Normalize",VectorNormalize1)
    .def("Normalize",nonstatic_Normalize)
    .def("Normalize",VectorNormalize3)

You can also def() the static normalize at module scope:

    def("Normalize", VectorNormalize2);

and then:

    >>> v = Vector()
    >>> Normalize(v)

which in many ways is a more natural interface anyway.


HTH,
-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com





More information about the Cplusplus-sig mailing list