C++ compiler error: ambiguous call to overloaded function

后端 未结 4 1563
-上瘾入骨i
-上瘾入骨i 2020-12-07 00:41
string aux;
int maxy,auxx=0;

cin>>aux;

maxy= (int)sqrt(aux.size());

I\'m geting:

1> error C2668: \'sqrt\' : ambiguous c         


        
4条回答
  •  再見小時候
    2020-12-07 01:15

    aux.size() returns an std::size_t, but sqrt() does not have an overloaded version that takes a std::size_t argument.

    The compiler reports that sqrt has 3 overloads: which take float, double and long double arguments. std::size_t could be converted to any of those, so there's an ambiguity since the compiler doesn't know whether to convert std::size_t to float or double or long double.

提交回复
热议问题