Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 921
Vasi Marin Avatar asked Jan 22 '26 08:01

Vasi Marin


1 Answers

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.

like image 135
Nicol Bolas Avatar answered Jan 25 '26 09:01

Nicol Bolas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!