[C++-sig] How do I wrap virtual methods
David Abrahams
dave at boost-consulting.com
Fri Aug 5 19:41:00 CEST 2005
Eric Jardim <ericjardim at gmail.com> writes:
> 2005/8/5, David Abrahams <dave at boost-consulting.com>:
>>
>> Does the tutorial really recommend that default_f? I can't imagine
>> why. That's just wrong; you don't need it and it's a bad idea to use
>> it. [Joel, can you please fix this ASAP, and the use of default_f
>> further down?]
My mistake; I was just mis-remembering. Please see:
http://mail.python.org/pipermail/c++-sig/2004-July/007844.html
[And my apologies to Joel]
> Beside the tutorial, Pyste itself generate "default_..." methods.
That is correct.
>> Another thing that I noticed is that I have to reimplement virtual methods
>> > on every derived class. This is an accumulative task. Am I right?
>>
>> I don't know what you mean.
>
>
> Suppose you have class A, B and C. C is derived from B, and B derived from A
> (A <- B <- C). Suppose you have a virtual method "f" (pure or not) defined
> on the A class scope. Suppose that you want to expose this method, so user
> can, in Python, extend some class (A, B or C)
>
> If you want to extend class A, in Python, that's Ok. When you create a new A p
> class in Python, you are actually creating a A_Wrapper object. But if you
> want to extend B or C, they don't know about the A_Wrapper. So, you must
> create B_Wrapper, C_Wrapper and re-expose "f" on both.
>
> Hope to make it clear now. Is this right, or not.
If you want to derive from B or C in Python and override "f" such that
when C++ calls it, the Python implementation is invoked, that's
correct.
> I still don't understand: should I use the "defaul_..." function (in a
> different way) or not use it?
Use it.
> Let's see a real (correct) example, please.
You can always know that the examples in libs/python/test are correct.
See libs/python/test/polymorphism2.cpp/.py
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list