[C++-sig] strange class_.def behaivior
Mike Rovner
mike at nospam.com
Fri Oct 10 02:53:50 CEST 2003
Hi,
I have an exception during loading a bpl extension module.
When bpl try to execute class_.def statement, class namespace object pointer
= 0.
In file src/object/function.cpp line 388 (add_to_namespace()) ns
uninitialized,
because class_ this->m_ptr = 0.
It looks like my mistake but where?
Regards,
Mike
Example code:
#include <boost/python.hpp>
using namespace boost::python;
struct Test
{
Test(int s=0) : size(s) {}
int Size() const {return size;}
int size;
};
static bool test_eq(const Test& t1, const Test& t2) { return t1.Size() ==
t2.Size(); }
template<class T>
struct Wrap
{
static class_<T>& PyClass(const char* name)
{
return
class_<T>(name)
.def(init<int>())
.def("__len__", &T::Size)
;
}
};
BOOST_PYTHON_MODULE(ext1)
{
Wrap<Test>::PyClass("Test").def("__eq__", &test_eq);
}
More information about the Cplusplus-sig
mailing list