Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

# Saving this for later?

### Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Standard text messaging rates apply

# Compile time polymorphism

3,052
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
3,052
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
49
0
Likes
2
Embeds 0
No embeds

No notes for slide

### Transcript

• 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. 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. 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. Different parameter typesvoid Function(int a) {}void Function(char a) {}void Function(double a){}
• 5. Different number of parametersint Function(int a) {}int Function(int a,char b){}int Function(int a,float b,long c) {}
• 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. 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. 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. 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.  Can perform variety of functions with same function name. No need to remember name of many functions.
• 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.  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.