3

I did not manage to figure out if constexpr implies also static in C++17.

I found this thread: constexpr vs. static const: Which one to prefer?

And I noticed this comment:

One more thing, in C++17, constexpr static data member variables will be inline too. That means you can omit the out of line definition of static constexpr variables, but not static const. 

Does the logic in the comment above imply that constexpr also has a static property in C++17?

The reason I opened a new thread about this topic is to have something that is clear.

From what I managed to investigate I think constexpr and static are separated.

Sorry if the problem is not well formulated or good.

1
  • You cannot define non-static constexpr variables in the class. Commented Sep 30, 2021 at 11:15

1 Answer 1

2

The only implicit storage property of a constexpr variable is inline, and only then if it is a constexpr static member variable.

You cannot declare a non-static constexpr member variable, but static is not implied; it is an explicit requirement.

Sign up to request clarification or add additional context in comments.

1 Comment

And for a non-member variable, let's say a global variable x: constexpr x and static constexpr x are two different things, no?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.