October 22nd, 2003, 12:05 AM
we can classify the Polmorphism are two types
1.Dynamic. Ex - Virtual Functions.
2.Static. Ex - Function Overloading.
But I have simple doubt. Operator Overloading is also belongs to
Is it correct ?.
Please Explain me.
October 22nd, 2003, 12:22 AM
Polymorphism is otherwise known as dynamic binding. It is always done through virtual function. During runtime it requires the use of vtable to determine which function to invoke. In addition, the subclass that implements the virtual function must also have the same function signature.
Function overloading doesn't do polymorphism. Since the function signature of overloaded functions are different, they are consider as different functions. During compilation, overloaded functions are mangled so that they are distinguished as different function.
If I am not wrong, the closest to static polymorphism is through the use of templates.
October 22nd, 2003, 03:12 AM
Definition (Polymorphism (1)) The concept of dynamic binding allows a variable to take different types dependent on the content at a particular time. This ability of a variable is called polymorphism.
Definition (Polymorphism (2)) If a function (or method) is defined by the combination of
·its name and
·the list of types of its parameters we speak of polymorphism.
Definition (Polymorphism (3)) Objects of superclasses can be filled with objects of their subclasses. Operators and methods of subclasses can be defined to be evaluated in two contexts:
1. Based on object type, leading to an evaluation within the scope of the superclass.
2. Based on object content, leading to an evaluation within the
scope of the contained subclass.
The second type is called polymorphism.
October 23rd, 2003, 07:00 PM
Some suggestions for nailing down these thoughts in your mind:
Dynamic binding is a data feature of the language that allows fuzzy typing.
Polymorphism is a feature of all object-oriented langauges and generally follows the principles discussed in this forum.
The definition of object-orientation is the ability to dynamically inherit and construct classeses based on a chosen inheritance; it doesn't necesarily pertain to super and sub-classes.
Finally, polymorphism can be a very elegant solution, but if you're new at it or are a little fuzzy, make sure you have someone really experienced over your shoulder, becuase the damage that can be done when improperly implemented can be very devastating.
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!