2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-29 19:52:16 +00:00

Make sure the class object and cast relationships are registered for

virtual function dispatch classes.


[SVN r19543]
This commit is contained in:
Dave Abrahams
2003-08-12 04:36:42 +00:00
parent 9c6650963f
commit 5008dcbdd4
7 changed files with 109 additions and 33 deletions

View File

@@ -52,6 +52,28 @@ struct C : A
virtual std::string f() { return "C::f()"; }
};
struct D : A
{
virtual std::string f() { return "D::f()"; }
std::string g() { return "D::g()"; }
};
struct DCallback : D, Callback
{
DCallback (PyObject* self) : Callback(self) {}
std::string f()
{
return call_method<std::string>(mSelf, "f");
}
std::string default_f()
{
return A::f();
}
};
A& getBCppObj ()
{
static B b;
@@ -79,6 +101,8 @@ C& getCCppObj ()
return c;
}
A* pass_a(A* x) { return x; }
BOOST_PYTHON_MODULE_INIT(polymorphism_ext)
{
class_<A,boost::noncopyable,ACallback>("A")
@@ -91,6 +115,13 @@ BOOST_PYTHON_MODULE_INIT(polymorphism_ext)
.def("f", &C::f)
;
class_<D,bases<A>,DCallback,boost::noncopyable>("D")
.def("f", &D::f, &DCallback::default_f)
.def("g", &D::g)
;
def("pass_a", &pass_a, return_internal_reference<>());
def("getCCppObj", getCCppObj, return_value_policy<reference_existing_object>());
def("factory", factory, return_value_policy<manage_new_object>());