C ++编译器错误:对重载函数的模糊调用 [英] C++ compiler error: ambiguous call to overloaded function
本文介绍了C ++编译器错误:对重载函数的模糊调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
string aux;
int maxy,auxx=0;
cin>>aux;
maxy= (int)sqrt(aux.size());
我要参加:
1> error C2668: 'sqrt' : ambiguous call to overloaded function
1> could be 'long double sqrt(long double)'
1> or 'float sqrt(float)'
1> or 'double sqrt(double)'
为什么?
推荐答案
string :: size()
返回 size_t
sqrt
不接受它的任何版本。所以编译器必须强制转换,并且不能选择什么 - 所有都是OK的。你必须显式转换:
string::size()
returns size_t
, and sqrt
doesn't accept it in any of its versions. So the compiler has to cast, and cannot choose to what - all of them are OK. You have to put explicit cast:
maxy = (int)sqrt((double)aux.size());
这篇关于C ++编译器错误:对重载函数的模糊调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文