Using a function doesn't require moving evaluation to runtime. Just add
constexpr
to the function and it will work at compile-time.const float _MOVEMENT_ = deg_to_rad(90);
will work even without aconstexpr
function, with the function you have right now.But it is advisable to:
Make it
static
to share it across all instances of the class.Make it
constexpr
(to make things easier)Rename so that it doesn't use a reserved identifier (any identifier starting with
_[A-Z]
or containing__
is reserved).Not name it in uppercase since it's not a macro (C/C++ uses uppercase for macros by convention, other languages tend to use it for constants since C macros often were used as constants, but it's weird IMO to make a full circle and use it for all constants in C/C++).
Same for the class name.
Overall, you end up with
static constexpr movement = deg_to_rad(90);
.
↧
Answer by HolyBlackCat for To evaluate constant in run time via function c++17
↧