[C++-sig] call_back and inheritance

David Abrahams dave at boost-consulting.com
Sat Aug 3 07:21:19 CEST 2002

Yes, Mike, I'm relieved to report that it's user error ;-)

A pure virtual function with no C++ implementation should be overridden in
the callback class to dispatch to Python via call_method<>, but should
never be exposed to Python with def().  After all, there's not supposed to
be an implementation there. The implementation of pureVirtualMethod you
exposed with def() gets found when you try to call it with call_method<>,
which of course finds the implementation of pureVirtualMethod you exposed
with def(), which you try to call with call_method<>, and so on until you
blow the stack.

I can't really understand why your Derived class is using call_method<>
directly to call pureVirtualMethod recursively on itself. That use of
call_method<> should really be reserved for callback classes.

Note also that the exception-handling stuff in the module init function is
superfluous. That's taken care of for you by the library.


           David Abrahams * Boost Consulting
dave at boost-consulting.com * http://www.boost-consulting.com

----- Original Message -----
From: "J. Michael Owen" <mikeowen at llnl.gov>
To: <c++-sig at python.org>
Sent: Friday, August 02, 2002 2:21 PM
Subject: [C++-sig] call_back and inheritance

> I'm running into a problem trying to use the call_back class idiom for
> virtual functions of classes for overriding from python.  The problem
> when I have a class with virtual functions I want to expose this way,
> inherits from another class that also has virtual functions and a
> call_back class to expose its methods.  When I do the obvious thing and
write a
> call_back class for this derived class, everything compiles OK but I get
> runtime SEGV when I try to use these methods.  I'm including an example
code and
> python script to exercise the problem -- is this a bug or just user
> Mike Owen.
> --
>  "Hey...where are the sunflower seeds?" |       J. Michael Owen
>         o_o /                           |       Phone:  925-423-7160
>         (")                             |       Email:  mikeowen at llnl.gov
>        \/'\/                            |

More information about the Cplusplus-sig mailing list