C++ Logo

std-discussion

Advanced search

Re: constexpr functions and variables

From: Federico Kircheis <federico_at_[hidden]>
Date: Wed, 3 Apr 2024 14:51:14 +0200
On Wed, Apr 03, 2024 at 12:06:46PM +0200, Jan Schultke wrote:
> > It is possible to declare a constant variable in a header file, and
>then have it constexpr in the translation unit?
>
>Yes; the "constexpr" applies to the full-expression of the
>initialization (https://eel.is/c++draft/dcl.constexpr#6), not to the
>object. It only makes the object "const". "constexpr" makes functions
>constexpr functions, so it cannot be applied only in one place and not
>the other because that would be an ODR violation.
>
>See also https://stackoverflow.com/q/30208685/5740428


I did not made a question, but a statement, the question mark was added
by you.


The question is why we cannot do something similar for functions

Received on 2024-04-03 12:51:22