Upcoming SlideShare
×

# Compile time polymorphism

5,255 views

Published on

Published in: Technology
2 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
5,255
On SlideShare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
82
0
Likes
2
Embeds 0
No embeds

No notes for slide

### Compile time polymorphism

1. 1.  Polymorphism means “many forms”.  Polymorphism means ability to take more than one form.  C++ implements polymorphism through Overloaded functions Overloaded operators Virtual functions.JPC and JWD © 2002 McGraw-Hill, Inc.
2. 2. A function name having severaldifferent definitions that aredifferentiable by the number or typeof their arguments,is known as anOVERLOADED FUNCTION and thisprocess is called FUNCTIONOVERLOADING.
3. 3. Functions to be overloaded must have same name. their parameter list must vary in: 1.in terms of number of arguments. 2.in type of arguments.
4. 4. Different parameter typesvoid Function(int a) {}void Function(char a) {}void Function(double a){}
5. 5. Different number of parametersint Function(int a) {}int Function(int a,char b){}int Function(int a,float b,long c) {}
6. 6. 1.While creating functions with same name if the signatures of subsequent functions match the previous function’s,then the second is treated as REDECLARATION of the first. For example: void square(int a,float b); void square(int x,float y);
7. 7. 2.While creating functions with same name if the signatures of the two functions match exactly but the return types differ,the second declaration is treated as an erroneous re-declaration of the first and is flagged at COMPILE time as an error. For example: float happy(float f); double happy(float x);
8. 8. Class abc { void main() int x;float y; { public: clrscr(); int max(int a,int b) float d;int c;{ abc o1,o2; if(a>b) c=o1.max(5,6); return a; printf("%d",c); else return b; } d=o2.max(10.0001); float max(float a) printf("%f",d);{ getch(); if(a>10) } return a; else return 10.00;}};
9. 9. class graphics{ float a,b; public: void main(){float area(float r){ float k; float x; clrscr(); x=3.14*r*r; graphics o1,o2; return x;} k=o1.area(10.0);float area(float l,float printf("%ft",k);b) { float y; k=o2.area(10.01,20.01); y=l*b; printf("%f",k); return(y); } }; getch();}
10. 10.  Can perform variety of functions with same function name. No need to remember name of many functions.
11. 11.  Functions should have different argument lists. Member functions cannot be overloaded solely on the basis of one being static and the other being non static.
12. 12.  C++ Sumita Arora 11th class. C++ Sumita Arora 12th class. Object –Oriented Modelling and Design with UML-James RumBaugh. Masters in C and C++ . OOP with Balaguruswamy.