[C++-sig] static class variables

David Abrahams dave at boost-consulting.com
Sat Mar 8 00:59:50 CET 2003


Francois Ostiguy <ostiguy at fnal.gov> writes:

> Hi -
>
> I recently experimented with the new "staticmethod" attribute to
> wrap static class methods. I works beautifully ... great work !

Thanks go mostly to Nikolay Mladenov, who contributed it.

> This leads me to ask: is there any existing/planned equally
> convenient way to wrap static class variables ?

See http://aspn.activestate.com/ASPN/Mail/Message/1547542, though I am
now favoring option 2 at the end of that message over option 1.  I
don't have a plan to implement it soon unless someone hires me to do
it, just because I have a lot on my plate already... but someone else
may want to do it.

> I am thinking of something along the lines of
>
> struct MyClass {
>    double value1;
>    double value2;

I assume you meant to add a static data member called 'value' here??

> }
>
>
> python::class_<MyClass>("MyClass")
>   .def_readwrite("value2", &MyClass::value)
>   .staticvariable("value2");                <<<<<< ?????????


That syntax would not be neccessary; it would be enough to write:

    python::class_<MyClass>("MyClass")
      .def_readwrite("value2", &MyClass::value)
      ;

...since &MyClass::value is not a data member pointer, but a simple
object pointer and thus we can deduce that it should act like a static
data member.

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





More information about the Cplusplus-sig mailing list