Sunday, July 16, 2006

Calling Polly - Polymorphism

'POLYMORPHISM' - The computer geek's buzz word.
one thing that drives the software industry is polymorphism! It is a very strong concept. To say, it is not as hard to master as it sounds, and at the same time it is not as easy to master as it seems from this statement. Boggled ?? Well dont be ! Lets make polymorphism simple.
POLYMORPHISM -> 1. FUNCTION OVERLOADING.
2. SCOPE RESOLUTION.
An easy way to understand things is to divide them into logical parts, ans as they say divide and rule....
1. Function overloading - this is what packs most of the punch.

Function overloading means using the same function name to call different functions according to need. It can be understood like this, your dining table functions as a table/surface on which food is served and eaten, while some times it also serves as table/surface on which the family board games are played. The world is full of such implementations of overloading. Your dad uses the computer to do his office work, you use it for playing games.
The point is that you use the same thing for different roles as per need.

int myfunc (int a, int b)
{
return (a+b);
}
int myfunc (char a, char b)
{
cout<}

here the functions have the same name but different parameter list and different body. With practice and further analysis you will understand it better.

2. Scope resolution - same variable name, but different variable (in distinct scope)

C++ provides a way to declare two variables having the same name but different their root scopes are disctinct, although they can overlap.

{ int a=1;
{
int a=2;
{
int a=3;
cout< }
}
}

Note: some programmers dont feel that scope res. should be called a part of polymorphism.

0 Comments:

Post a Comment

<< Home