I am having a trouble in this example.Whenever I send any arguments,it gives compiler error:
prog.cpp: In function ‘int main()’:
prog.cpp:11: error: call of overloaded ‘add(std::basic_istream<char, std::char_traits<char> >&, std::basic_istream<char, std::char_traits<char> >&)’ is ambiguous
prog.cpp:4: note: candidates are: int add(int, int) <near match>
prog.cpp:6: note: char add(char, char) <near match>
I personally think that this error should occur when I am sending the arguments as int's or char's but when I send float arguments,the error still remains.Please help.Thanks
/*Function Overloading*/
#include<iostream>
using namespace std;
int add(int a,int b);
float add(float a,float b);
char add(char a,char b);
int main()
{
float a,b;
cout<<"Enter Two numbers to add them"<<'\n';
add(cin>>a,cin>>b);
return 0;
}
int add(int a,int b)
{
//cin>>a,b;
return a+b;
}
float add(float a,float b)
{
//cin>>a,b;
return a+b;
}
char add(char a,char b)
{
//cin>>a,b;
return a+b;
}