关于sqrt函数 error C2668: 'sqrt' : ambiguous call to overloaded function
2013-09-09 22:27
766 查看
废话不多说直接上错误信息:
1>------ 已启动生成: 项目: Prime, 配置: Debug Win32 ------
1>正在编译...
1>TestPrime.cpp
1>d:\my documents\visual studio 2005\myprojects\prime\prime\testprime.cpp(49) : error C2668: 'sqrt' : ambiguous call to overloaded function
1> d:\vs2005\vc\include\math.h(581): could be 'long double sqrt(long double)'
1> d:\vs2005\vc\include\math.h(533): or 'float sqrt(float)'
1> d:\vs2005\vc\include\math.h(128): or 'double sqrt(double)'
1> while trying to match the argument list '(int)'
1>生成日志保存在“file://d:\My Documents\Visual Studio 2005\MyProjects\Prime\Prime\Debug\BuildLog.htm”
1>Prime - 1 个错误,0 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========
该错误显示sqrt函数后面参数只能是long double 、float或者double类型的数据,如果给它一个整形的参数,系统报错,不知道该用哪个。这时就需要我们来想办法了。
#include < iostream >
using namespace std;
#include < cmath >
#include "stdlib.h"
int main()
{
cout << int (sqrt(float(15)));//此项为解决项
//cout<<sqrt(15);//此项为报错项
system("pause");
return 0;
}
我用的是VS2005,C++编程。想让开平方后结果任然是整形需要强制转换成一个sqrt不产生歧义的方法。如上本人先把整形 15 转为 float型,然后把开方后的结果强制转化成int型。
1>------ 已启动生成: 项目: Prime, 配置: Debug Win32 ------
1>正在编译...
1>TestPrime.cpp
1>d:\my documents\visual studio 2005\myprojects\prime\prime\testprime.cpp(49) : error C2668: 'sqrt' : ambiguous call to overloaded function
1> d:\vs2005\vc\include\math.h(581): could be 'long double sqrt(long double)'
1> d:\vs2005\vc\include\math.h(533): or 'float sqrt(float)'
1> d:\vs2005\vc\include\math.h(128): or 'double sqrt(double)'
1> while trying to match the argument list '(int)'
1>生成日志保存在“file://d:\My Documents\Visual Studio 2005\MyProjects\Prime\Prime\Debug\BuildLog.htm”
1>Prime - 1 个错误,0 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========
该错误显示sqrt函数后面参数只能是long double 、float或者double类型的数据,如果给它一个整形的参数,系统报错,不知道该用哪个。这时就需要我们来想办法了。
#include < iostream >
using namespace std;
#include < cmath >
#include "stdlib.h"
int main()
{
cout << int (sqrt(float(15)));//此项为解决项
//cout<<sqrt(15);//此项为报错项
system("pause");
return 0;
}
我用的是VS2005,C++编程。想让开平方后结果任然是整形需要强制转换成一个sqrt不产生歧义的方法。如上本人先把整形 15 转为 float型,然后把开方后的结果强制转化成int型。
相关文章推荐
- error C2668: ‘sqrt’ : ambiguous call to overloaded function
- C2668: 'sqrt' : ambiguous call to overloaded function(sqrt问题)
- 函数重载二义性:error C2668: 'pow' : ambiguous call to overloaded function
- error C2668: 'abs' : ambiguous call to overloaded function
- 【关于DrawLine' : ambiguous call to overloaded function解决办法】
- error C2668: ‘pow’ : ambiguous call to overloaded function
- error C2668: 'sqrt' : ambiguous call to overloaded
- 'sqtr'ambiguous call to overloaded function
- ambiguous call to overloaded function解决的办法
- ambiguous call to overloaded function错误分析及解决方法
- ambiguous call to overloaded function 两种情况的错误分析及解决方法
- ambiguous call to overloaded function
- error: no matching function for call to ‘boost::thread::thread(<unresolved overloaded function type>
- Qt error ------ no matching function for call to QObject::connect(QSpinBox*&, <unresolved overloaded function type>, QSlider*&, void (QAbstractSlider::*)(int))
- 关于Call to undefined function mysql_connect()错误的解决方法
- 关于socket_create 报错,call to undefined function socket_create()的可能的解决方案。
- 关于MAC下php出现:Call to undefined function Think\imagettftext()的解决办法
- error: no matching function for call to ‘ptr_fun(<unresolved overloaded function type>)’
- 关于NetBean 下PHP的 Fatal error: Call to undefined function curl_init() in F:\phpdemo\Apache24\htdocs\ms
- 关于MAC下php出现:Call to undefined function Think\imagettftext()的解决办法