V
V
Vadim Ushakov2022-02-05 13:38:03
C++ / C#
Vadim Ushakov, 2022-02-05 13:38:03

Initializing union from two enumerations?

struct AggregationTypeAndMetalNonMetalTransitionData {
    PrimaryElementGroupType primarygrouptype; // Тип группы элемента.
    union {
        SecondaryElementGroupMetalType _metal; // Подгруппы металлов.
        NonMetalSecondaryGroupType _nonmetal; // Подгруппы неметаллов.
    } secondarytype;
    StateOfAggregationType stateofaggregation; // Агрегатное состояние вещества.
};


{PrimaryElementGroupType::nonmetals, NonMetalSecondaryGroupType::nonmetal, StateOfAggregationType::Gas}


The second initialization option does not work. Mistake
k6ewDIJ.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2022-02-05
@Nightmare1

The second initialization option does not work

Well, yes, it doesn't work. Thus, only the first element of the union can be initialized. There is also such an initialization option, starting with C ++ 20.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question