Could Python supplant Java?
Bernhard Herzog
bh at intevation.de
Fri Aug 23 14:42:35 EDT 2002
"James J. Besemer" <jb at cascade-sys.com> writes:
> Casts are NOT automatically generated for pointers, so the following
> code WILL exhibit the expected Polymorphism without virtual functions
> (classes A and B as above):
>
> void foo( A* arg ){
> arg.x;
> arg.bar(); // calls A or B depending on type of arg
> }
>
> A a; B b;
>
> foo( &a ); // foo will call A.bar()
> foo( &b ); // foo will call B.bar()
No, foo(&b) will call A::bar unless bar is virtual.
[...]
> Paul Foley wrote:
>
> > And just what do you think your C++ vtable lookup is?
>
> > You've failed to demonstrate that. You had to resort to late binding,
> > via `virtual', to get polymorphism in C++
[...]
> "Early binding" generally means resolved at or before link time.
However, which virtual method bar is called in a function like this
void foo(A * a)
{
a->bar();
}
Is *not* determined at link time.
Bernhard
--
Intevation GmbH http://intevation.de/
Sketch http://sketch.sourceforge.net/
MapIt! http://www.mapit.de/
More information about the Python-list
mailing list