How to overload function in cpp

Overload Function In cpp

PROGRAM:

  1. #include<iostream>
  2. using namespace std;
  3. void sub(float i,float j){
  4. cout<<"\nsub : "<<(i-j);
  5. }
  6. void sub(int i,int j){
  7. cout<<"\nsub : "<<(i-j);
  8. }
  9. void add(int i,int j){
  10. cout<<"\nadd :"<<(i+j);
  11. }
  12. void add(float i,float j){
  13. cout<<"\nadd :"<<(i+j);
  14. }
  15.  
  16. int main(){
  17. int a,b,ad;
  18. float x,y;
  19. cout<<"integer value are : ";
  20. cin>>a>>b;
  21. cout<<"float value are : ";
  22. cin>>x>>y;
  23. add(a,b);
  24. add(x,y);//!arguments have different data types
  25. sub(a,b);
  26. sub(x,y);//!!arguments have different data types
  27. return 0;
  28. }
  29.  

Comments

Popular posts from this blog

Introduction to ChatGPT: Explain what ChatGPT is, how it works, and what it is used for.

Multi Level Inheritance In cpp

Hybrid Inheritance In cpp