C++ compiler error: ambiguous call to overloaded function

后端 未结 4 1588
-上瘾入骨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:11

    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());
    

提交回复
热议问题