[C++-sig] Re: deriving in python from a C++ base class

Stefan Seefeld seefeld at sympatico.ca
Sun Jul 6 21:35:46 CEST 2003


David Abrahams wrote:

>>"Because C++ object construction is a one-step operation, C++
>>  instance data cannot be constructed until the arguments are available
>>in the __init__ function..."
>>
>>This and the following paragraphs make some very important points.
> 
> 
> Could you be specific about the ending point of the text you'd like
> to see incorporated as well as the beginning point?
> 
> 
>>As a C++ programmer I'm used to a specific object model / type system,
>>so I believe it would be very useful to discuss how that maps to python,
>>and how boost.python does the dispatching.
> 
> 
> That's not really in the paper, is it?

no. When I ran into the problem with the non-initialized base class,
it was Ralf who pointed me to this paper (see the beginning of this thread).
Reading the cited paragraph, I started to understand the problem. That
made me curious so I tried calling __init__ multiple times, so I discovered
that multiple base objects were bound to my derived class.

I'v been working with python for quite some time, but in this particular
context with a C++ base class this cought my attention, as this is obviously
something were the C++ and the python way of life differ dramatically.

That's why I'd like to see some discussion of these issues.

>>Ok. But I do believe that it should be explained. Forgetting to call
>>__init__ on the base class may be a common error, especially for C++
>>programmers who are used to things like default constructors.
> 
> 
> That's a good idea.  Joel, what do you think about mentioning in the
> tutorial that wrapped C++ objects are created by calling their
> __init__ functions?

May be if the tutorial stays as it is, but at appropriate places you
point to some special chapters with a 'for details see...' icon, covering
particular topics such as this in depth.

Thanks a lot !

		Stefan





More information about the Cplusplus-sig mailing list