0

I was writing a floating point comparison function using templates:

template<class T>
    static bool AlmostEqual(T f1, T f2) 

I had a statement such as:

T min_value = std::numeric_limits<T>::min();

For some reason the compiler treats the min above as a function pointer and issues the error:

   ../include/CommonFunctions.h: In static member function ‘static bool CommonFunctions::AlmostEqual(T, T) [with T = double]’:
file.cpp:2200:   instantiated from here
../include/CommonFunctions.h:22: error: cannot convert ‘double (*)()throw ()’ to ‘double’ in initialization

The static function is defined as part of a big program. But, when I put the same function in a standalone file and compile and use it, I see no error. I read other posts and tried something like this:

T min_value(std::numeric_limits<T>::min());

I still get the same error and also one more:

../include/CommonFunctions.h:22:53: error: macro "min" requires 2 arguments, but only 1 given

In one error, it is able to resolve the min as a function correctly and in another error it is being treated as a macro. I'm not sure, how to resolve this issue. Any pointers would be appreciated?

cppcoder
  • 1,194
  • 4
  • 16
  • 30

1 Answers1

3

For people including windows.h, put the following in effected headers:

#include windows headers ...

pragma push_macro("min")
pragma push_macro("max")
#undef min
#undef max

#include headers expecting std::min/std::max ...

...

pragma pop_macro("min")
pragma pop_macro("max")

In source files just #undef min and max.

#include windows headers ...

#undef min
#undef max

#include headers expecting std::min/std::max ...