0
Please Help me
Overloaded function gets error https://code.sololearn.com/ceYvtS6Q1E66/?ref=app
3 Answers
+ 3
#include<iostream>
//overload the swap function for int and float
void swap(int *a , int *b);
void swap(float *a , float *b);
int main()
{
int i1 = 3 , i2 = 5;
float f1 = 3.55f , f2 = 8.22f;
std::cout << "\n integers Before Swap : " << std::endl;
std::cout << i1 << ", " << i2 << std::endl;
swap (&i1 , &i2);
std::cout << "\n integers After Swap : " << std::endl;
std::cout << i1 << "," << i2 << std::endl ;
std::cout << "\n floating points Before Swap : " << std::endl;
std::cout << f1 << ", " << f2 << std::endl;
swap (&f1 , &f2);
std::cout << "\n floating points After Swap :"<< std::endl;
std::cout << f1 << "," << f2 << std::endl ;
return 0;
}
//an integer swap function
void swap (int *a , int *b)
{
int temp = *a ;
*a = *b;
*b = temp ;
}
//an overloaded float swap function
void swap (float *a , float *b)
{
float temp = *a ;
*a = *b;
*b = temp;
}
+ 2
In function declartion you have used pass by reference
(void swap(float&,float&))
but in function definition you have used pointers
0
Correct code try to understand if not tell me



