Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2001-04-10 12:25:18


Hi,

In future please indicate in the subject line which of the boost libraries
you're writing about.

----- Original Message -----
From: <thedent_at_[hidden]>

> Hi,
> I'am using a 3d-engine, which has some important members declared as
> static member variables.
> But MSVC6 seems to be not capable to compile the code, if i try
> to "def_readonly" them.
> I get the error described below:
>
> class foo {
> public:
> static float bar;
> };
>
> python::class_builder<foo> foo_class(this_module, "foo");
>
> foo_class.def_readonly(&foo::bar, "foobar");
> ^^^
> error C2784: 'void __thiscall boost::python::class_builder<class
> foo,class boost::python::detail::held_instance<class foo>
> >::def_readonly( foo::*,const char *)'
> : could not deduce template argument for ' foo::*' from 'float *'
>
> If I remove the static declaration, everything works fine!
>
> Same, if I try to include a global variable as a member variable:
>
> int g_test = 0;
> python::class_builder<foo> foo_class(this_module, "foo");
> foo_class.def_readonly(&g_test, "foobar");
>
> Any Idea how to use the static member variable (which is, as i
> understand, sort of a global variable with limited scope)

Well, it's not surprising; there's no support for this built-in
Not a bad idea, though; please add it to the feature request list at
SourceForge.
THe best workaround I can think of would be something like this:

    float foobar(Foo const*) { return foo::bar; }
    ...
    foo_class.def(foobar, "__getattr__foobar__");

which would produce a similar result.

Regards,
Dave


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk