What's the difference between static constexpr and static inline variables in C++17?

Viewed 20408

With C++17 we get inline variables.

One of the uses for them is to define constant fields in classes.

So what's the difference between these two constant definitions:

class MyClass {
    static constexpr int myFirstVar = 10;
    static const inline int mySecondVar = 100;
};

Of course constexpr makes myFirstVar implicitly inline.

What's the better choice here, to use constexpr or inline?

Note: when you don't need constness, then inline makes it easier. With constexpr you don't have that choice.

1 Answers
Related