注册 登录
编程论坛 C++教室

大家帮忙看看,“sqrt”: 对重载函数的调用不明确

tianya0802 发布于 2012-04-25 08:30, 838 次点击
#include<iostream>
#include<math.h>
using namespace std;
void main()
{
   int i=1,num;
   double root;
   while(i<=10)
   {
       cout <<"请输入正整数:";
       cout<<'\n';
       cin>>num;
       if(num<0)
       {
       cout<<"负数,请重新输入正整数!\n";
       continue;
       }
       root=sqrt(num);   //“sqrt”: 对重载函数的调用不明确
       cout<<root<<endl;
       i++;
   }

}
请高手指点一下,为什么一编译,就会报“sqrt”: 对重载函数的调用不明确。谢谢各位大侠
2 回复
#2
rjsp2012-04-25 12:08
嗯,因为编译器不知道你想将 num 转化为 float,然后调用 float sqrt( float x );
还是想将 num 转化为 double,然后调用 double sqrt( double x );
#3
wsgzg2012-04-25 16:36
二楼正解!需要进行显示类型转换
1