Revision 2 as of 2002-11-18 18:36:38

Clear message

class_<> statement constructs python class object.

Usually it's included in BOOST_PYTHON_MODULE to wrap C++ class:

class A { ... };
BOOST_PYTHON_MODULE(example)
{
  class_<A>("A");
}

Also it can be used explicitly to create class instances from C++:

BOOST_PYTHON_MODULE(example1)
{
  object class_a = class_<A>("A");

  object instance_a = class_a();
}

If you want to forbid creating class instancies from python, you now must pass no_init to class_<> definition. Default, as in python, will be init with no arguments. There is no limit to number of init<>'s in the boost.python.

Synopsis:

class_<A>("A")
    .def(init<int, int>())
    .def(...)
    ;

class_<B>("B", init<int, int>())
    .def(...)
    ;

class_<C>("C", "C's docstring", init<int, int>())
    .def(...)
    ;

class_<D>("D", "D's docstring", init<int, int>(), "__init__ doc")
    .def(...) 
    ;


class_<E>("E")
    .def(...)
    ;

class_<F>("F", no_init)
    .def(...)
    ;

class_<G>("G", "G's docstring", no_init)
    .def(...) 
    ;

class_<H>("H", "H's docstring")
    .def(...) 
    ;

Unable to edit the page? See the FrontPage for instructions.