[C++-sig] def_init required
Achim Domma
achim.domma at syynx.de
Wed May 22 22:23:03 CEST 2002
Hi,
see below a small test extension. If I don't call def_init on
class_<HelloWorld> I can load the extension and create an object, but if I
call 'showIt', I get the following error:
TypeError: bad argument type for built-in operation
Is def_init required for each class?
Achim
---- code -----
#include <boost/python/module.hpp>
#include <boost/python/class.hpp>
#include <iostream>
struct HelloWorld {
HelloWorld(){};
void showIt() {
std::cout << "Hello World";
}
};
BOOST_PYTHON_MODULE_INIT(HelloWorld)
{
using namespace boost::python;
module m("HelloWorld");
m.add(
class_<HelloWorld>("HelloWorld")
.def_init() // if missing -> type error
.def("showIt",&HelloWorld::showIt)
);
}
---- code -----
More information about the Cplusplus-sig
mailing list