Jump to content

C++ Language/Preprocessing/CompileTimeConstants

From Wikibooks, open books for an open world

In C++ syntax, there are some quantities that must be known while your compiler is compiling. In those situations, you could use expression 1+2 (because the compiler is able to perform arithmetic while it's compiling), but function calling is too complex of an activity to occur during compilation (unless that function's features are radically stripped-down). Use keyword constexpr to mark a stripped-down function that might be "called" during compilation, or a variable which might be "evaluated" during compilation.

Additional information about compile-time constants (includes interactive examples)