[C++-sig] python namespace

David Abrahams dave at boost-consulting.com
Thu Nov 21 23:40:01 CET 2002

"Bjorn Pettersen" <BPettersen at NAREX.com> writes:

>> From: David Abrahams [mailto:dave at boost-consulting.com] 
>> "Achim Domma" <achim.domma at syynx.de> writes:
>> >   scope drawable = scope(object(inner_module))
>> Why are you messing around with that approach when I already 
>> posted this correct one?
>>     scope drawable(object(inner_module));
> Now I'm confused... If I use the following code:
>   handle<> db_module(PyModule_New("db"));
>   scope().attr("db") = db_module;
>   scope db_scope = object(db_module);      /**/
>   class_<X>("X");
> X ends up in nrx.db (my main module is named nrx) and everything works
> as expected. If I change the line marked /**/ to:
>   scope db_scope(object(db_module));
> X ends up in nrx and there's an empty nrx.db. To add to the confusion, I
> thought:
>   A a = B(x);
> was equivalent to:
>   A a(B(x));

it is, unless A's constructor is explicit.

> is my C++ really that rusty?

Naw. Well, maybe. It's confusing. I was wrong, sorry. The correct line

   scope db_scope((object(db_module)));

The other one, without the extra parens, declares a function :(

To see that, note that the following compiles:

    struct scope {};
    struct object {};

    int main() {
       scope db_scope(object(db_module));


Hmm, maybe it wasn't such a good idea to make scope's constructor
explicit. I give up!! Any suggestions for the proper interface to
scope will be gratefully considered!

                       David Abrahams
   dave at boost-consulting.com * http://www.boost-consulting.com
Boost support, enhancements, training, and commercial distribution

More information about the Cplusplus-sig mailing list