OOP / language design question
Lawrence D'Oliveiro
ldo at geek-central.gen.new_zealand
Thu Apr 27 03:40:03 EDT 2006
In article <Xns97B092B9B6512duncanbooth at 127.0.0.1>,
Duncan Booth <duncan.booth at invalid.invalid> wrote:
>Carl Banks wrote:
>
>> You know, Python's __init__ has almost the same semantics as C++
>> constructors (they both initialize something that's already been
>> allocated in memory, and neither can return a substitute object).
>
>There is a significant difference: imagine B is a base type and C a
>subclass of B:
>
>When you create an object of type C in Python, while B.__init__ is
>executing self is an object of type C (albeit without all the attributes
>you expect on your C).
>
>In C++ when the B() constructor is executing the object is an object of
>type B. It doesn't become a C object until the C() constructor is
>executing.
>
>In other words, the object is constructed in Python before any __init__ is
>called, but in C++ it isn't constructed until after all the base class
>constructors have returned.
But if "construction" is what a constructor does, then you're wrong.
More information about the Python-list
mailing list