polymorphism

Helmut Jarausch jarausch at igpm.rwth-aachen.de
Wed May 14 06:06:30 EDT 2003


Haris Bogdanovic wrote:
> How is polymorphism implemented in Python ?
> Is there a substitution for C++ virtual functions ?
> Can you give me a short example of how this works ?

You cannot compare Python to C++.
In C++ a parameter to a function is strongly typed
so that you can only pass arguments of exactly the
same type or a type with a predefined conversion.
So you can pass a pointer to a derived class to a
function parameter which expects a pointer to
(some) base class of this derived class.
This is when virtual functions come into play.
Other cases as mentioned in this thread are just
hiding of names defined in a base class.

Since Python is not a typed language you can pass
an object to function which the author of the function
even didn't dream of when he/she was writing the
function. But that's the typical situation what
virtual functions are meant for in C++ .

-- 
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany





More information about the Python-list mailing list