Vasi Marin
Vasi Marin

Reputation: 483

A variable/data member of a class declared constexpr in C++17 is also static?

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.

Upvotes: 3

Views: 146

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 474316

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.

Upvotes: 2

Related Questions