[C++-sig] How do I wrap virtual methods

Eric Jardim ericjardim at gmail.com
Fri Aug 5 19:18:27 CEST 2005


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?]


Beside the tutorial, Pyste itself generate "default_..." methods.

> 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 
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.

Everything the tutorial says, aside from the definition and use of
> default_f, seems to be right.
> 

It looks like the docs use the "default_..." functions too: 
http://www.boost.org/libs/python/doc/v2/wrapper.html

I still don't understand: should I use the "defaul_..." function (in a 
different way) or not use it?

Let's see a real (correct) example, please.

Thanks,

[Eric Jardim]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20050805/ee06f2c0/attachment.htm>


More information about the Cplusplus-sig mailing list