原题是使用重载函数的方法定义两个函数,用来分别求出两个int型数的点间距离和浮点型数的点间距离。
#include<iostream.h>
#include<math.h>
int distan(int,int);
float distan(float,float);
void main()
{
int distance1;
float distance2;
distance1=distan(1,2);
distance2=distan(1.35,2.78);//出错处
cout<<distance1<<distance2;
}
int distan(int x,int y)
{
int c=abs(x-y);
return c;
}
float distan(float x,float y)
{
float c=abs(x-y);//错误处
return c;
}
d:\vc++ 6.0\myprojects\p1299\p7.cpp(10) : error C2668: 'distan' : ambiguous call to overloaded function
d:\vc++ 6.0\myprojects\p1299\p7.cpp(20) : warning C4244: 'argument' : conversion from 'float' to 'int', possible loss of data
d:\vc++ 6.0\myprojects\p1299\p7.cpp(20) : warning C4244: 'initializing' : conversion from 'int' to 'float', possible loss of data
.请高手帮帮忙指点一下 小弟感激不尽
[求助]重载函数的问题