[C++-sig] Problems using wrapper.hpp to override virtual functions
Tim Spens
t_spens at yahoo.com
Fri Jan 18 23:08:26 CET 2008
Your right I didn't want to derive the class from the variable (strange that all the examples I've seen have it this way?).
I've changed this and I'm no longer getting the error. But when the virtual function is invoked in c++ my overridden python class
is still not being called?
Thanks for the help,
Tim
----- Original Message ----
From: Roman Yakovenko <roman.yakovenko at gmail.com>
To: Development of Python/C++ integration <c++-sig at python.org>
Sent: Friday, January 18, 2008 1:21:10 PM
Subject: Re: [C++-sig] Problems using wrapper.hpp to override virtual functions
On Jan 18, 2008 10:12 PM, Tim Spens <t_spens at yahoo.com> wrote:
> Here is a complete simple example that shows the same error.
>
> #include <boost/python.hpp>
> #include <boost/python/module.hpp>
> #include <boost/python/class.hpp>
> #include <boost/python/wrapper.hpp>
> #include <boost/python/call.hpp>
> using namespace boost::python;
>
> // Class with one pure virtual function
> struct P {
> virtual ~P(){}
> virtual char const* f() = 0;
> char const* g() { return "P::g()"; }
> };
>
> struct PCallback : P, wrapper<P> {
> char const* f() {
> return this->get_override("f")();
> }
> };
>
> // Class with one non-pure virtual function
> struct A {
> virtual ~A(){}
> virtual char const* f() { return "A::f()"; }
> };
>
> struct ACallback : A, wrapper<A> {
> char const* f() {
> if (override f = this->get_override("f"))
> return f();
> return A::f();
> }
> char const* default_f() { return this->A::f(); }
> };
>
> int main() { return 0; }
>
> BOOST_PYTHON_MODULE_INIT(callback) {
> class_<PCallback,boost::noncopyable>("P")
> .def("f", boost::python::pure_virtual(&P::f));
> class_<ACallback,boost::noncopyable>("A")
> .def("f", &A::f, &ACallback::default_f);
> }
>
> >>> import callback
> >>> b = callback.P()
> >>> class derived(b):
Is this intentional to create Python class that derived from variable?
I guess you wanted to write
class derived( callback.P ):
Am I right?
--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/
_______________________________________________
C++-sig mailing list
C++-sig at python.org
http://mail.python.org/mailman/listinfo/c++-sig
____________________________________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs
More information about the Cplusplus-sig
mailing list