3ec516dc   
   From: daniel.kruegler@googlemail.com   
      
   On 2011-09-21 00:09, Fulvio Esposito wrote:   
   > On Tuesday, September 20, 2011 3:42:23 PM UTC+2, ptyxs wrote:   
   >> #include   
   >> #include   
   >>   
   >> int main()   
   >> {   
   >> int a = 25;   
   >> std::cout<< sqrt(a)<< std::endl;   
   >> }   
   >>   
   >>   
   >> How is it ?   
   >> Thanks for any enlightenment.   
   >   
   > Vc++ 2010 gives effectively a compiler error. The reason is not for the   
   > integer type of the argument, but for ambiguity in overload resolution.   
   > there's an implicit conversion from int to all of the three types that   
   > sqrt provides an overload. And this result in an ambiguity call!   
      
   This result would be expected for a C++03-conforming compiler, but not   
   for a C++11-conforming one.   
      
   > But libstdc++ (used by gcc) has this definition in math.h   
   >   
   > template __gnu_cxx::__enable_if< __is_integer<   
   > _Tp>::__value, double   
   >> ::__type sin (_Tp __x)   
   >   
   > that enable sqrt for integral type resolving the ambiguity. I heven't got   
   > a copy of the standard, so I cannot say if it's required this overload.   
      
   In C++11 the example code is supposed to be well-formed, it is required   
   by [c.math] p11 which says that integer arguments shall behave as if   
   they would be provided as double values.   
      
   HTH & Greetings from Bremen,   
      
   Daniel Krügler   
      
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|