Initialize enum value when calling function

Is it possible to initialize an enum value like this:

enum Test
    X = function("X")


I am currently getting this error in Visual Studio:

error C2057: Constant expression expected

And Visual Studio doesn't support constexpr


source to share

1 answer

The list of enums in an enumeration declaration is defined as follows:

list-list is a comma-separated list of enumeration definitions, each of which is either just an identifier that becomes the name of the enumerator, or an identifier with an initializer: identifier = constexpr

You can only use constant expressions.



All Articles