static const int dimension = 10;void foo() array;..However, I acquire the compile error: "expression must have a consistent value", even though dimension is a constant. I can use the macro

#define dimension (10)But ns am wonder why size significant const reasons compilation error.

You are watching: C++ expression must have a constant value

In C language keyword const has nothing to do with constants. In C language, by an interpretation the ax "constant" refers to literal values and enum constants. This is what you need to use if girlfriend really require a constant: either usage a literal value (define a macro to provide your constant a name), or usage a enum constant.

(Read right here for much more details: shall I like constants over defines?)

Also, in C99 and also later execution of the language it possible to use non-constant values as selection sizes for local arrays. That means that her code should compile in modern C also though your dimension is no a constant. But you are reportedly using an older compiler, for this reason in her case

#define dimension 10is the right way to go.

Sunday, august 15, 2021

answered 3 Months ago
Magic Enum header-only library offers static reflection because that enums (to string, from string, iteration) because that C++17.

#include enum color RED = 2, BLUE = 4, environment-friendly = 8 ;Color color = Color::RED;auto color_name = magic_enum::enum_name(color);// color_name -> "RED"std::string color_name"GREEN";auto shade = magic_enum::enum_cast(color_name)if (color.has_value()) // color.value() -> Color::GREEN;For much more examples check home repository

Where is the drawback?

This library supplies a compiler-specific hack (based ~ above __PRETTY_FUNCTION__ / __FUNCSIG__), which works on Clang >= 5, MSVC >= 15.3 and also GCC >= 9.

Enum value should be in variety .


If need another selection for all enum species by default, redefine the macro MAGIC_ENUM_RANGE_MIN and also MAGIC_ENUM_RANGE_MAX.

MAGIC_ENUM_RANGE_MIN should be less or equates to than 0 and must be higher than INT16_MIN.

MAGIC_ENUM_RANGE_MAX should be greater than 0 and also must be much less than INT16_MAX.

See more: Tavern Brawl: Clash Of The Minions Tavern Brawl Deck : Clash Of The Minions

If require another range for particular enum type, add specialization enum_range for necessary enum type.

#include enum number one = 100, 2 = 200, three = 300 ;namespace magic_enum template struct enum_range static constexpr int min = 100; static constexpr int max = 300;;