Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2001-03-16 19:40:36


> Hi,
>
> I'm new to boost, but have a small problem with this interesting piece of
> software. I couldn't get the enum_as_int stuff working (possibly because I use
> serveicepack 3 with MSVC6), so I decided to store the enums in ints myself
> (class member variables). However there were two more things I tried to do, but
> couldn't get to work. First I tries a my_module.def_readonly(...) but it look
> like only my_class.def_readonly(...) is supported (my question is: why?)

Well, essentially because modules don't have an overridable __getattr__ method
slot, so the only way to put things at module scope is to add attributes to the
module dictionary. Python dictionaries don't have read-only elements.

> The
> second thing I tried was making the variables static to the class, like so:
>
> class aclass
> {
> public:
> static int n;
> }
> aclass::n=123;
> my_class.def_readonly(&aclass::n, "n");
>
> However: I got this compiler message:
>
> D:\TigerVR\Code\Pussy\vr6.cpp(232) : error C2784: 'void __thiscall
> boost::python::class_builder<class key,class
> boost::python::detail::held_instance<class key> >::def_readonly( key::*,const
> char *)' : could not deduce template argument for ' key::*' from 'int *'
>
>
> Any way to do what I want?

It's hard to know without seeing your error messages. I think the
enum_as_int_converters should work, probably even with SP3. The incantation in
the Boost.Python comprehensive test looks something like this:

namespace boost { namespace python {
  template class enum_as_int_converters<MyEnum>;
}}

Good Luck,
Dave


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