[C++-sig] registration order

Roman Yakovenko roman.yakovenko at gmail.com
Thu Feb 9 07:23:26 CET 2006


Hi.
Please take a look on next code:

struct item{
    explicit item( int i )
    : m_value( i )
    {}

    int m_value;
};

struct container{
public:

    explicit container( const item& x = item( 2 ) )
    : my_item( x )
    {}

    item my_item;
};

BOOST_PYTHON_MODULE(class_order){
    bp::class_< container >( "container"
                                        , bp::init< item const & >((
bp::arg("x")=item( 1 ) ) ) )
      .def_readwrite( "my_item", &container::my_item );

    bp::class_< item >( "item"
          , bp::init< int >(( bp::arg("i") ) ) )
        .def_readwrite( "m_value", &item::m_value );
}

Module class_order can not be loaded. The reason is that

bp::arg("x")=::class_order::item( 1 )

expression requires class "item" to be already registered.

I see from the doc

Class arg operator =
template <class T> arg &operator = (T const &value);
Requires: The argument must convertible to python.

that this is intentional behaviour. Is it possible to remove this requirement?

Thanks.
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/



More information about the Cplusplus-sig mailing list