c++ overload 3 function with different parameters(int,*int,&int)

Viewed 673

So i have this homework to do "Using functions overloading define 3 functions with the same name but with different prams type (int, int*, int&) that will return the square root of the value." Well i made it but i don't know it gives me this error:"ambiguous call to overloaded function". I try to fix it but no succes... Here's my code it's quite simple:

#define _CRT_SECURE_NO_WARNINGS
#include <math.h>
#include <iostream>
using namespace std;

double rad(int);
double rad(int*);
double rad(int&);

int main(){
int a,*pt=&a;
cin>>a;
cout<<"Radical din "<<a<<" este "<<rad(a)<<endl;
cout<<"Radical din "<<a<<" este "<<rad(pt)<<endl;
cout<<"Radical din "<<a<<" este "<<rad(&a)<<endl;
return 0;
}

double rad(int x){
    return  (sqrt(x));
}
double rad(int *x){
    return  (sqrt(*x));
}
double rad(int &x){
    return  (sqrt(x));
}
4 Answers
Related