[C++-sig] Re: sub module support in V2

David Abrahams david.abrahams at rcn.com
Mon Jun 10 20:41:03 CEST 2002


From: "Dave Hawkes" <daveh at cadlink.com>


> Here is the latest diff that includes the nested class support. I've also
> rearranged and tidied up a few items. Nested classes can be created
before
> their parents without error.
>
> However I'm not sure that I like it.
>
> maybe instead of:
>
>     class_<ctest>("ctest")
>         .def_init()
>         .def("set_v", &ctest::set_v);
>     class_<ctest::ctest2>("ctest.ctest2")
>         .def_init()
>         .def_readwrite("n", &ctest::ctest2::n);
>
> we should do:
>
>     class_<ctest>("ctest")
>         .def_init()
>         .def("set_v", &ctest::set_v);
>         .def("ctest2", class_<ctest::ctest2>());
>     class_<ctest::ctest2>()
>         .def_init()
>         .def_readwrite("n", &ctest::ctest2::n);

I guess I didn't make myself clear earlier. I was suggesting

    class_<ctest> c("ctest")
        .def_init()
        .def("set_v", &ctest::set_v);
        ;

    class_<ctest::ctest2>("ctest2", c)
        .def_init()
        .def_readwrite("n", &ctest::ctest2::n)
        ;


which nicely enforces the existence of c before ctest2 is declared.

> This could be achieved as once a particular class has been registered we
can
> find its object from the typeinfo, rather than by name.

Why do you prefer your second approach? Seems messier than the first to me.






More information about the Cplusplus-sig mailing list