How to overload function in cpp

Overload Function In cpp

PROGRAM:

#include<iostream>
using namespace std;
void sub(float i,float j){
    cout<<"\nsub : "<<(i-j);
}
void sub(int i,int j){
    cout<<"\nsub : "<<(i-j);
}
void add(int i,int j){
    cout<<"\nadd :"<<(i+j);
}
void add(float i,float j){
    cout<<"\nadd :"<<(i+j);
}

int main(){
int a,b,ad;
float x,y;
cout<<"integer value are : ";
cin>>a>>b;
cout<<"float value are : ";
cin>>x>>y;
add(a,b);
add(x,y);//!arguments have different data types
sub(a,b);
sub(x,y);//!!arguments have different data types
return 0;
}

 
 

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