The keyword constexpr was introduced in C++11 and improved in C++14. It means constant expression. Like const, it can be applied to variables so that a compiler error will be raised if any code attempts to modify the value. Unlike const
, constexpr
can also be applied to functions and class constructors. constexpr
indicates that the value, or return value, is constant and, if possible, will be computed at compile time. A constexpr
integral value can be used wherever a const
integer is required, such as in template arguments and array declarations. And when a value can be computed at compile time instead of run time, it can help your program can run faster and use less memory. check this
The constexpr
is not supported in vs2010
, but it’s supported on vs2015
, check this to know what’s supported on vs
, actually vs2010
is not fully support of C++11
, so you may update your compiler here.
So you may use vs2015 or you may not use the constexpr
here, and you may check this link to see what’s the difference between the const
and constexpr
, so if possible to use const
instead of constexpr
is possible for you.
The mainly difference between them as in the previous link is:
-
const applies for variables, and prevents them from being modified in your code.
-
constexpr tells the compiler that this expression results in a compile time constant value, so it can be used in places like array lengths, assigning to const variables, etc.
solved This code is not compiling c++