So I read the interesting answers about what are the differences between constexpr and const but I was curious about are the differences between #define and constexpr ? I feel like constexpr is just a #define where the type can be chosen.
You are quite correct.
#define
(also called a 'macro') is simply a text substitution that happens during preprocessor phase, before the actual compiler. And it is obviously not typed.
constexpr
on the other hand, happens during actual parsing. And it is indeed typed.
Comes without saying that, wherever you can, using constexpr
is a bit safer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With