   Can't use math.h functions in my class
  Although I included math.h file I can't use abs() function. However I can use memcpy() function of memory.h file; I have no problem with that. (When I comment the line "#include <memory.h>", it gives "`abs' undeclared" error, as expected) What am I doing wrong here?Compiler gives the following error :Quote:195 C:\Prog\SAVE\wxDevCPP\MD5\MD5.cpp `abs' undeclared (first use this function) Class definition in MD5.h file :#include <math.h>#include <memory.h>class CMD5{private:// ...// ...void Encode(unsigned int * H0, unsigned int * H1, unsigned int * H2, unsigned int * H3);// ...// ...public:// ...// ...};The relevant member funcion in MD5.cpp file :void CMD5::Encode(unsigned int * Hash0, unsigned int * Hash1, unsigned int * Hash2, unsigned int * Hash3){// ...// ...for (int i=0; i<64; i++) K = (unsigned int) abs((long double) sin(i + 1) * pow((long double) 2, (long double) 32));// ...// ...}
  I have no problem with sin() and pow() functions.Previously I tried using cout to give an output message inside the class and gave a similar error, something like "cout undefined" although I wrote "using namespace std;" previously.Do you think that these two error could be related?   ;Quote:Original post by BattousaiI have no problem with sin() and pow() functions.Previously I tried using cout to give an output message inside the class and gave a similar error, something like "cout undefined" although I wrote "using namespace std;" previously.Do you think that these two error could be related?Maybe.  It's possible you have a macro somewhere treading all over your code.The functions abs() in C++ is found in the the header <cmath> (and the function memcpy() is found in the header <cstring>).  It's possible that (a) the use of the wrong header introduces preprocessor macro wickedness into the global namespace and the resulting cancer is killing your program, or (2) there is no supported overload for the type long double.  I don't recall seeing that type mentioned in the C++ standard, but it might be in the part that  puts me to sleep while reading.-smw   ;  Check this link : http://www.cplusplus.com/reference/clibrary/cmath/It looks like math.h doesn't have abs() function declared in it. fabs() is declared instead.It is a Visual C++ API function : http://msdn2.microsoft.com/en-us/library/kw1ee768(VS.80).aspxfabs() : http://msdn2.microsoft.com/en-us/library/18z15bk0(VS.80).aspx;Quote:Original post by BattousaiCheck this link : http://www.cplusplus.com/reference/clibrary/cmath/It looks like math.h doesn't have abs() function declared in it. fabs() is declared instead.Or, check ISO/IEC 14882:2003(E) [26.5] Table 83 (header <cmath> synopsis).  If your standard library does not provide std::abs() specialized on types long, float, double, and long double, it is non-conforming and ought to be thrown away.  Find yourself an implementation that's less than a decade out of date.  There are plenty available.You might need to realize that the C standard library header <math.h> and the C++ standard library header <cmath> are two different headers with different contents corresponding to different language standards and requirements.Quote:It is a Visual C++ API function : http://msdn2.microsoft.com/en-us/library/kw1ee768(VS.80).aspxfabs() : http://msdn2.microsoft.com/en-us/library/18z15bk0(VS.80).aspxNeither abs() nor fabs() are Windows API functions.  The std::abs() functions are C++ standard library functions found in <cmath>.  The function float fabs(float) is a C standard library function found in <math.h>.Try just including <cmath> and using std::abs() to see if it fixes your problem.