ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> cpp-sig
cpp-sig
Re: [C++-sig] Re: Boost.Python : Byref parameters - no problems with static/non-static overloading
by Joel Gerard other posts by this author
Sep 30 2003 2:12PM messages near this date
[C++-sig] Re: Boost.Python : Byref parameters - no problems with static/non-static overloading | [C++-sig] Two Pyste suggestions
Ok.  I've got things mostly sorted out.  You can't overload static and non-static member
functions, which is fine, but how do you use a static (not overloaded) function in Python? I
 need
to keep the static function in the class scope. The reason is name collision, i.e.

class A
{
   static void foo();
}

class B 
{
   static void foo();
}

I have:
class Vector
{
public:
    static  void        Orthonormalize          (Vector& kU, Vector& kV, Vector& kW);
}

Wrapped as:


void (*Orthonormalize2)(Vector&, Vector&, Vector&)      = &Vector::Orthonormalize;
.def("Orthonormalize",Orthonormalize2)
            .staticmethod("Orthonormalize")

In python, do you just use it as an unbound method?  Is the self argument non-existent in th
is
case, or do I do something different?

Currently I have:
Vector.Orthonormalize (Vector1, Vector2, Vector3)

Also, is there a good place to look for python examples. I didn't see a python example in th
e
docs, but perhaps there is something else? 

Thanks,
Joel

--- David Abrahams <>  wrote:
>  Joel Gerard <> writes:
>  
>  > Thanks for the advice. There are a few things I'm still vague on though. I've been overl
oading
>  > 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.
>  
>  Both are calling CreateCross2.
>  
>  > Regarding the vector problem. I cannot modify the original C++ code.  I want to keep Nor
malize
>  as
>  > an unbound method in Vector since I might have name collisions if I
>  > put them at the module level. 
>  
>  What collisions?  There's overloading at the module level too, you
>  know.
>  
>  > I tried .def("Yahoo",Normalize3) but it too gave me a type
>  > error. What is Boost trying to do? 
>  
>  I have no idea; post a reproducible test case.
>  
>  Maybe you forgot to make it static?
>  
>  > 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? 
>  
>  No.
>  
>  > Does Boost automatically detect this?
>  
>  It does detect that they are references.
>  
>  > 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?
>  
>  argument error, but that's because Python ints are immutable.  Classes
>  don't play by the same rules.
>  
>  > I think I'm missing something fundamental here... :(
>  >
>  > Thanks for your help.
>  > Joel
>  
>  Sure thing.
>  
>  -- 
>  Dave Abrahams
>  Boost Consulting
>  www.boost-consulting.com
>  
>  
>  _______________________________________________
>  C++-sig mailing list
>  C++-sig@[...].org
>  http://mail.python.org/mailman/listinfo/c++-sig


=====
--------------------------------------
Email: joelgerard@[...].com

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

_______________________________________________
C++-sig mailing list
C++-sig@[...].org
http://mail.python.org/mailman/listinfo/c++-sig
Thread:
David Abrahams
Joel Gerard

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved