How to specialize a generic enum in Swift?

Why are enum const values accessible outside the block in which the enum is defined?

  • struct tagged_union { enum {INT, FLOAT, STRING} type; int integer; float floating_point; char *string; } tu; /* Why INT accessible here? */ tu.type = INT; tu.integer = 100;

  • Answer:

    You tagged this with both C++ and C, but that "INT" is only accessible in C. In a C++ program, INT is a member of tagged_union and you would have to write tu.type = tu.INT; or tu.type=tagged_union::INT; In a C program, INT is an enumerator constant whose scope is the block scope in which the tagged_union's declaration is located. There simply isn't a struct scope in C and enumerators are not struct members in C.

Sergey Zubkov at Quora Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.