[C++-sig] Static, again...

Scott A. Smith ssmith at magnet.fsu.edu
Thu Dec 5 03:05:54 CET 2002


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? 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? As I recall,
using the static method in Python via the class name worked OK in
BPV1. I cannot get function getDims() working in V2 with anything I've
tried. Can someone spell it out for me?

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

Scott






More information about the Cplusplus-sig mailing list