Design a template function for swapping the int, double and char type values between two variables. Note: Use function overloading.
#include<iostream>
using namespace std;
void template(int a, int b){
int temp=a;
a=b;
b=a;
}
void template(double a,double b){
double temp=a;
a=b;
b=temp;
}
void template(char a, char b){
char temp=a;
a=b;
b=a;
}
int main(){
template(5,10);
template(5.10,10.5);
template('a','b');
return 0;
}
Comments
Leave a comment