c++ - sqrt() pow() fabs() do not work -


i trying compile program using functions sqrt pow , fabs. have math.h included reason errors like:

    error c2668: 'fabs' : ambiguous call overloaded function 

same rest of functions have included:

    #include "stdafx.h"     #include "math.h" 

i tried including still same errors. know why not being recognized? file .cpp not .c mfc project.

thanks

it's because functions overloaded several types: float, double , long double. thus, if pass in integer, compiler doesn't 1 choose. easy fix pass double (or multiply pass in 1.0), should fix problem.

      int value = rand();       int result1 = (int)fabs(value*1.0);        printf("%d, %d\n", result1, result1); 

otherwise:

     int value = rand();      int result1 = (int)fabs((double)value);       printf("%d, %d\n", result1, result1); 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -