Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Cannot convert 'double (*)() noexcept' to 'double' in initialization' when defining a max double

Tags:

c++

I read that the standard C++ way of using the maximum double value is std::numeric_limits<double>::max.

Then in each of my functions where I want to initialize my doubles as the max double I use:

#include <limits>
#define MAX_DOUBLE (std::numeric_limits<double>::max)

Using gcc -pedantic -pedantic-errors -Wall -Wextra -Werror, I get the following error:

Cannot convert 'double (*)() noexcept' to 'double' in initialization

Can you explain this error?

like image 704
Guillaume Ansanay-Alex Avatar asked Apr 23 '15 09:04

Guillaume Ansanay-Alex


1 Answers

Just as the error message said, you're using a function pointer (double (*)() noexcept) as a double directly. std::numeric_limits<double>::max is declared as a function, you need to call it to get the value.

You can change

#define MAX_DOUBLE (std::numeric_limits<double>::max)

to

#define MAX_DOUBLE (std::numeric_limits<double>::max())
like image 159
songyuanyao Avatar answered Sep 29 '22 06:09

songyuanyao