[C++-sig] Re: Boost.Python : Byref parameters - no problems with static/non-static overloading
Joel Gerard
llywelyn.geo at yahoo.com
Mon Sep 29 19:05:36 CEST 2003
Thanks for the advice. There are a few things I'm still vague on though. I've been overloading
static, and non-static members without apparent problems, but I'm now starting to be suspicious.
For instance, I have:
Vector (Vector::*CreateCross1)(const Vector&) const = &Vector::CreateCross ;
Vector (*CreateCross2)(const Vector&, const Vector&) = &Vector::CreateCross;
.def("CreateCross",CreateCross1)
.def("CreateCross",CreateCross2)
The one I call as a bound method, and the other unbound, i.e.:
Vector2 = Vector1.CreateCross(Vector3)
Vector2 = module.Vector.CreateCross(Vector1,Vector3)
Is something going on here that I'm not seeing. They work ok apparently.
Regarding the vector problem. I cannot modify the original C++ code. I want to keep Normalize as
an unbound method in Vector since I might have name collisions if I put them at the module level.
I tried .def("Yahoo",Normalize3) but it too gave me a type error. What is Boost trying to do? The
function pointer is poiting to the correct function.
Furthermore, don't you have to do something different than just a plain .def since the arguments
to Normalize are references? Does Boost automatically detect this? How does it deal with
something like:
Add(int x, int y, int &result)
So when you do >>>Add(x,y,result) in python, what happens?
I think I'm missing something fundamental here... :(
Thanks for your help.
Joel
--- David Abrahams <> wrote:
> "Mike Rovner" <> 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
>
>
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig
__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com
More information about the Cplusplus-sig
mailing list