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

Hugo van der Merwe hugo at adept.co.za
Wed Nov 13 07:51:12 CET 2002

> Unfortunately, no. That would be cool, though, wouldn't it?  I'm
> pretty sure you can do this after you define class_<Settings>, though:
>     // Note no leading dot.
>     def("Settings", &Settings::GetInstance
>         , return_value_policy<reference_existing_object>());
> This will replace the class in the module by a function called
> Settings that gets the instance.

Yes, that worked beautifully! Now I just do (in Python):

Settings().detailThreshold = 10
Settings().verbose = true

Just found it hard to decide whether I should keep the Python wrapper
as close as possible to the C++ library and use "SetVerbose" and
"GetVerbose", or whether to use Boost.Python's really nifty
properties. Well, I couldn't resist! ;)

Do properties currently only handle straight forward single parameter
"setters"? How difficult would it be to allow it to do two parameters,
with e.g. "object.property[5] = 10"? (Or can it do that already?)

> I think that's right. However, I wonder if we should change the
> __init__ function that you get from no_init to be a no-op unless the
> Python class actually has the same type as the abstract base...

Sounds like an idea ...

Thanks again!
Hugo van der Merwe

More information about the Cplusplus-sig mailing list