What is the difference between static and constexpr?

I understand that the constexpr variable can be used in compiletime. For example, for a template or static helper.

But if I want to do this without constexpr, I can with static const .

What is it since C ++ 11/14 introduced constexpr the difference between

 constexpr int a = 3; //AND static const int a = 3; 

Thanks!

Another way to see this question is: which should I use?

+7
c ++ c ++ 11 static-variables constexpr
source share
1 answer

The main difference that I know is that the value of constexpr must be known at compile time, and const static can be assigned at runtime.

 const static int x = rand(); 
+10
source share

All Articles