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] Static, again...
by David Abrahams other posts by this author
Dec 5 2002 2:21AM messages near this date
[C++-sig] Static, again... | RE: [C++-sig] Static, again...
"Scott A. Smith" <ssmith@[...].edu>  writes:

>  I also have looked over the mailing list archives and 
>  still don't see how things work. The example given was
> 
> > #include <boost/python/module.hpp>
> > #include <boost/python/class.hpp>
> >
> > struct Num {
> >    Num() {}
> >    ~Num() {}
> >    static int getDims() {return 3;}
> >    int dims() {return 5;}
> > };
> >
> > BOOST_PYTHON_MODULE_INIT(numTest)
> > {
> >    using namespace boost::python;
> >    module numTestMod("numTest");
> >    numTestMod
> >       .add
> >       ( class_<Num>("Num")
> >         .def_init()
> >         .def("getDims",&Num::getDims)
> >         .def("dims", &Num::dims)
> >         )
> >       ;
> > }
> 
>  Was the conclusion in this discussion that one cannot
>  use getDims with an instance of the class NOR with the
>  class itself? That is neither
> 
>  X = Num()
>  X.getDims()
> 
>  nor
> 
>  Num.getDims()
> 
>  will work? 

I don't know if we concluded that, but it's correct.

>  Neither works for me. David wrote that
> 
> > We don't have a way to make true static methods yet.
> 
>  So, what ways are there for using the static method? 

A static member function is just a regular function; you can add it at
module scope:

BOOST_PYTHON_MODULE_INIT(numTest)
{
   def("getDims", &Num::getDims);
   ...
}

>  As I recall, using the static method in Python via the class name
>  worked OK in BPV1. 

I think that's correct.

>  I cannot get function getDims() working in V2 with anything I've
>  tried. Can someone spell it out for me?

See above.

>  Thanks, (and thanks to Dave twice over in a single day)

If it's any consolation, I now know exactly what needs to be done to
support static methods. It's just a matter of finding time and/or
funding to do the work...

-- 
                       David Abrahams
   dave@[...].com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution


_______________________________________________
C++-sig mailing list
C++-sig@[...].org
http://mail.python.org/mailman/listinfo/c++-sig
Thread:
Hugo van der Merwe
Scott A. Smith
David Abrahams
Scott A. Smith
Nicodemus
Scott A. Smith
Mike Rovner
David Abrahams
David Abrahams
Hugo van der Merwe
Hugo van der Merwe
David Abrahams
Hugo van der Merwe
David Abrahams

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