Difference between struct and enum?

后端 未结 4 1361
名媛妹妹
名媛妹妹 2020-12-14 19:06

I am newbie to C++, and want to understand what is the difference between saying

typedef enum stateUpdateReasonCode
{
    a=1,
    b=2,
    c=3
} StateUpdate         


        
4条回答
  •  北海茫月
    2020-12-14 19:52

    enum work like the constants where you want to specify the the value with a word. Like for the days of week one want that sun = 0, mon = 1 and so on. In this case enum can be used.

    struct is totally different from the enum. It can be seen analogues to the class in c++ or any other programming language. structure is a user defined data type which can be used to store the info. Like in address different fields can be there street , zip code etc.

    the first one compiles as it stores the value of an enum and second one does not as struct variable data members values can be assigned by creating a struct variable.

提交回复
热议问题